2012-07-18 60 views
0

我有一個站點使用窗口onbeforeunload函數,但點擊彈出不起作用,因爲它。我怎麼可以在彈出的代碼集成的代碼禁用窗口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

這似乎是工作,與正在打開鏈接之前放置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> 
+0

我試過了,但沒有奏效 – 2012-07-18 17:43:49

+0

我用一個適合我的版本更新了答案,你可以再試一次嗎? – mogelbrod 2012-07-18 17:54:49

+0

是它的工作感謝,但彈出窗口是在同一窗口中打開 – 2012-07-18 18:02:22