简体   繁体   English

覆盖onbeforeunload(javascript)

[英]Override onbeforeunload (javascript)

I try to override window.onbeforeunload of this link http://lpfr.quizir.com/lp.aspx?LpID=332354&PartnerID=weedo 我尝试覆盖该链接的window.onbeforeunload http://lpfr.quizir.com/lp.aspx?LpID=332354&PartnerID=weedo

The script is located here : http://lpfr.quizir.com/scripts/exittraffic.js window.onbeforeunload = DisplayExitSplash; 脚本位于此处: http : //lpfr.quizir.com/scripts/exittraffic.js window.onbeforeunload = DisplayExitSplash;

This link is open in a popup, then when I tried to change the link in the popup or close the popup, I can't. 该链接在弹出窗口中打开,然后当我尝试更改弹出窗口中的链接或关闭弹出窗口时,我无法打开。

var xwin = window.open(http://lpfr.quizir.com/lp.aspx?LpID=332354&PartnerID=weedo)

Generally, this works: xwin.onbeforeunload = function(){} 通常,这xwin.onbeforeunload = function(){}xwin.onbeforeunload = function(){}

But it doesn't work on this specific link >_< 但这不适用于该特定链接> _ <

Does anyone have any idea? 有人有什么主意吗?

onbeforeunload you can just use operators and return because of preventing people from spamming. 在onbeforeunload之前,您可以只使用运算符并返回,因为这样可以防止垃圾邮件。

So you can't use window.scrollTo , window.alert and document.location.href . 因此,您不能使用window.scrollTowindow.alertdocument.location.href

Just spammers want to use these functions onbeforeunload. 只是垃圾邮件发送者想在卸载前使用这些功能。 Remember the client want to leave the page and don't want to close alert windows and get redirected. 请记住,客户端希望离开页面,并且不想关闭警报窗口并获得重定向。

To remove all handlers for that event you should remove the DOM level 0 event like: 要删除该事件的所有处理程序,应删除DOM level 0事件,例如:

window.onbeforeunload = null;

like Nico sugests 像尼科糖一样

But also the other ways of event handling like so. 而且还有其他类似的事件处理方式。

Depending on what browser you use you could do 根据您使用的浏览器,您可以做什么

window.removeEventListener( "beforeunload" );

On Chrome Firefox and other "W3c compliant browsers" or 在Chrome Firefox和其他“与W3c兼容的浏览器”上,或

window.detachEvent( "onbeforeunload" );

On Internet Explorer 6 (i think) and up. 在Internet Explorer 6(我认为)上。

我已经执行过此操作,离开页面没有任何问题

window.onbeforeunload = null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM