我只想在浏览器窗口关闭时打开一个新的弹出窗口。 我有以下代码,但它似乎没有工作
<script type="text/javascript">
window.onbeforeunload = function () {
window.open("http://www.w3schools.com");
}
</script>
感谢
答案 0 :(得分:0)
您正在寻找onUnload
事件,而不是onBeforeUnload
。
onBeforeUnload
应返回在自动确认窗口中使用的字符串。
警告,大多数弹出窗口拦截器会忽略从window.open
事件执行的onUnload
来电。
请参阅the mdc documentation here for onUnload
和here for onBeforeUnload
。
答案 1 :(得分:0)
您设置为window.onbeforeunload的函数必须返回一个字符串,该字符串将在消息框中显示给用户。
window.onbeforeunload = function () {
window.open("http://www.w3schools.com");
return "something";
}