[英]Javascript Class using the window.onunload event
我有一个带有方法和属性的javascript类。
是否可以将此类连接到pageunload事件?
当用户移动页面时,我试图在类中调用一个方法。
我怎样才能做到这一点。
谢谢
从onbeforeunload
事件处理程序返回一个字符串将显示一个对话框。
<html>
<head>
</head>
<body>
test
<script>
window.onbeforeunload = function () {
return "*** Warning: changes are not saved! ***";
};
</script>
</body>
</html>
在Internet Explorer中,此对话框如下所示:
---------------------------
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
---------------------------
您的文本将夹在某些浏览器特定的文本之间,但这是唯一的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.