开发者

Javascript Class using the window.onunload event

I have a javascript class with methods and properties.

Is it possible to wire this class up to a pageunload event?

I am开发者_如何学JAVA trying to call a method in my class when the user moves pages.

How can I do this.

Thanks


Returning a string from the onbeforeunload event handler will show a dialog box.

<html>
<head>
</head>
<body>
test
<script>
window.onbeforeunload = function () {
   return "*** Warning: changes are not saved! ***";
};
</script>
</body>
</html>

In internet explorer this dialog looks like this:

---------------------------
Windows Internet Explorer
---------------------------
Are you sure you want to navigate away from this page?

*** Warning: changes are not saved! ***

Press OK to continue, or Cancel to stay on the current page.
---------------------------
OK   Cancel   
---------------------------

Your text will be sandwiched between some browser specific text, but that is the only way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜