我有一个使用窗口onbeforeunload功能的网站,但点击弹出因为它不起作用。我该如何整合代码
window.onbeforeunload="null";
在下面的弹出代码中
<script type='text/javascript'>
function ouvre(fichier) {
ff=window.open(fichier,"popup","width=600px,height=300px,left=50%,top=50%") //this._try = 1; setTimeout('this._try = 1;', 4000); } function playMovie(_try) { if (this._try == 1) { playlavideo(); } else { alert('You must share the video to play.'); } }
</script>
<a href="#" onClick="ouvre('http://www.facebook.com/sharer.php?u=http://google.com/');return false"><img src="http://i.imgur.com/GnqwI.jpg" width="500" height="145" border="0"></a>
答案 0 :(得分:0)
这似乎有效,关键更改是在打开链接之前放置window.onbeforeunload=null
。
<script type='text/javascript'>
// Set a beforeunload callback
window.onbeforeunload = function() { return false; };
function open_popup(url) {
window.open(url,"popup","width=600px,height=300px,left=50%,top=50%");
return false;
}
</script>
<a href="http://www.facebook.com/sharer.php?u=http://google.com/" onClick="window.onbeforeunload=null;return open_popup(this.href);"><img src="http://i.imgur.com/GnqwI.jpg" width="500" height="145" border="0"></a>