主窗口关闭时重定向弹出窗口 [英] Redirect popup on main window close

查看:73
本文介绍了主窗口关闭时重定向弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

A pop up is opened when a user clicks a button. This pop up will go to a holding page, and wait for the user to leave the website or close the browser.

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

Then when the user leaves or closes the browser, it will redirect the pop up location to a different site.

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

I have tried several variants of the following code:

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并不精彩,所以任何有关如何使这项工作的帮助都将深表感谢。

But without luck. I am not brilliant with javascript /jquery so any help on how to make this work would be deeply appreciated.

谢谢!

推荐答案

我知道你已经有一个原型工作,但如果你想要jquery选项:

I know you already have a prototype working, but if you want the jquery option:

var popup = window.open('http://google.com', 'popup');

$(window).unload(function() {
    if(!popup.closed) {
        popup.location.href = 'http://surveyurl.com/';
    }
});

您还应检查是否存在popup.closed。

You should also be checking to see if popup.closed is there.

这篇关于主窗口关闭时重定向弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆