gpt4 book ai didi

javascript - 主窗口关闭时重定向弹出窗口

转载 作者:行者123 更新时间:2023-11-28 21:05:07 24 4
gpt4 key购买 nike

当用户单击按钮时,将打开一个弹出窗口。此弹出窗口将转到等待页面,并等待用户离开网站或关闭浏览器。

然后,当用户离开或关闭浏览器时,它会将弹出位置重定向到不同的站点。

我尝试了以下代码的几种变体:

win=window.open('google.com','popup'); //just to illustrate the "win" = my window.open().

$(window).bind('beforeunload', function() {
window.win.location.href="http://the-new-location.com";
//tried something like this as well:
//win.location.href="http://the-new-location.com";
});

但运气不好。我对 javascript/jquery 并不擅长,所以任何有关如何完成这项工作的帮助将不胜感激。

谢谢!

最佳答案

我找到了解决方案:

win=window.open('google.com','popup');

window.onunload = redirect;
function redirect(){
window.win.location.href="http://the-new-url.com";
};

关于javascript - 主窗口关闭时重定向弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10089034/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com