下面的代码有什么问题?
<script language="javascript">
function abreJanela() {
var janela = window.open("http://www.google.com", "janela", "width=700, height=600");
janela.onbeforeunload = function() {
alert("Windows was closed");
}
}
</script>
最佳答案
onbeforeunload
的目的是返回一个字符串,(通常)用于提示用户。其他操作,如 alert
,可能会(通常会)被忽略。请看the Mozilla Developer Network documentation :
Since 25 May 2011, the HTML5 specification states that calls to window.alert(), window.confirm(), and window.prompt() methods may be ignored during this event. See the HTML5 specification for more details.
关于Javascript:onbeforeunload 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30179244/