0
我有一個退出彈出式js函數,它顯示警告並在有人試圖離開頁面時向url中添加內容(並重定向)。JavaScript退出彈出式功能在Chrome和IE中無法正常工作
警報顯示在所有的瀏覽器,但代碼:
window.location.href = "?p=exit"
在Chrome和IE不執行。
它在Firefox正常工作。當您重新加載頁面時,會顯示警報並且修改網址。
看看源代碼,它非常簡單。
代碼:
<!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" />
<script type="text/javascript">
var exit=true;
function confirmExit()
{
if(exit)
{
window.location.href = "?p=exit";
}
if(exit)
return "Wait! Don't Leave Empty Handed!\n\nThank you for taking the time to check out our offer! Before you go we have a complimentary crash to help you succeed. Click the 'Cancel' or 'Stay On This Page' button if you're interested!";
}
</script>
</head>
<body onbeforeunload="return confirmExit()">
</body>
</html>
請不要使用簽名或標語在您的文章,否則將被removed.http://stackoverflow.com/faq#signatures – Pankaj 2012-04-20 08:09:20
能你在你的問題中粘貼一些相關的代碼? – 2012-04-20 08:30:00
添加了代碼。 – Zolka 2012-04-20 08:58:16