正在爲類進行項目工作,我想要一個javascript事件,該頁面加載時彈出,當用戶導航時彈出。我試圖通過onload
和onunload
事件直接嵌入到我的html中來處理它,但它似乎並沒有在Chrome上工作,而在Internet Explorer上,我似乎只能得到卸載消息。代碼如下:頁面加載時的Javascript提醒以及頁面退出時的提醒
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>teest</title>
<!-- [if lt IE 9]>
<script src = "http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif] -->
<link rel="stylesheet" href="css/contact.css" />
<meta name="viewport" content="width=device-width,initial-scale=1.0"> <!-- viewport tag configuration -->
<link rel="shortcut icon" href="img/favicon.ico" />
</head>
<body onload = "alert('Even if you aren't interested, please give our design some feedback as we would like to stay current.')" onunload = "alert('Thank you for your time and consideration!')">
<header class = "head">
<h1>
<img src="img/coa.png" display="inline-block" height="150px" float="left"/>
other stuff</h1>
<p>stuffsy</p>
</header>
可能的複製或頁面刷新?](http://stackoverflow.com/questions/13443503/run-javascript-code-on-window-close-or-page-refresh) – Bassie
[文檔的卸載事件](https://開發人員.mozilla.org/en-US/docs/Web/Events/unload)指出「UI inter操作無效(window.open,alert,confirm等)「,所以你不能在onunload中使用alert。 – user2313067