当用户单击按钮时,将打开一个弹出窗口。 此弹出窗口将转到等待页面,并等待用户离开网站或关闭浏览器。
然后,当用户离开或关闭浏览器时,它会将弹出位置重定向到不同的站点。
我尝试了以下代码的几种变体:
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/