2011-01-12 47 views
1

我已經嘗試了下面的代碼提到的目的,但這不是在mozila中工作,而且我在確認框中獲得一些額外的行。在瀏覽器上獲取確認框關閉

<html> 
<head>  
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> <title>Coordinates!</title> 
<script type="text/javascript"> 
var myclose = false; 
function ConfirmClose()   
{     
    if (event.clientY < 0) 
    {       
    event.returnValue = 'Any message you want'; 
    setTimeout('myclose=false',100); 
    myclose=true;     
}   
}   
function HandleOnClose()   
{     
if (myclose==true) 
alert("Window is closed");   
} 
</script> 


    </head> <body onbeforeunload="ConfirmClose()" onunload="HandleOnClose()" ><a href="#">test</a> </body></html> 

請問您能爲mozila建議些什麼。

+1

請修復格式和拼寫。 – Migol 2011-01-12 09:45:26

回答

1

如果您嘗試在用戶嘗試從頁面導航時顯示彈出窗口,則可以使用,甚至還有跨瀏覽器解決方案。但是,如果你試圖做的是從JavaScript調用來查看Firefox是否退出,我不認爲這是可能的JavaScript ...然後我可能再次錯誤。

function goodbye(e) { 
    if(!e) e = window.event; 
    //e.cancelBubble is supported by IE - this will kill the bubbling process. 
    e.cancelBubble = true; 
    e.returnValue = 'You sure you want to leave?'; 

    //e.stopPropagation works in Firefox. 
    if (e.stopPropagation) { 
     e.stopPropagation(); 
     e.preventDefault(); 
    } 
} 
window.onbeforeunload=goodbye; 

source

1

可以實現使用jQuery相同。

檢查this示例。在文本框關閉窗口中輸入內容。