2012-05-19 55 views
0

我想知道如果用戶離開之前頁面加載完成,但我後頁加載完成,因爲我有點麻煩,因爲我不知道如何禁用它。 這是一個搜索加載頁面的一部分,所以當頁面加載完成後,用戶被重定向到結果頁面,但是通過這個腳本,用戶被詢問他是否想在搜索完成後離開頁面。 代碼是波紋管,並且在頁面加載未完成時以及完成時都適用。 關於如何在頁面加載結束之前只觸發此事件的任何想法或有任何其他方式來完成此任務?onbeforeunload觸發彈出只有當onload沒有完成

謝謝。

<?php 

$var = <<<EOF 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Title</title> 
    <script language="JavaScript"> 
     window.onbeforeunload = confirmExit; 
     function confirmExit() 
     { 
     return "message?"; 
     } 
    </script> 
</head> 
<body> 
asdf 
</body> 
</html> 

EOF; 

    print $var; 
    flush(); 
    ob_flush();  
$i = 0; 
while($i < 10){ 
    print $i.'<br />'; 
    flush(); 
    ob_flush();  
    sleep(1); 
    $i++; 
} 

?> 

回答

0
window.onload = function(){ 
    // Called once the page is fully loaded to make onbeforeunload a no-op 
    window.onbeforeunload = null; 
} 

確認這是文件中的第一個功能,所以它得到第一個約束。