gpt4 book ai didi

javascript - JavaScript 返回确认

转载 作者:行者123 更新时间:2023-11-28 12:39:01 25 4
gpt4 key购买 nike

我在 Chrome 中遇到返回确认问题。在 Firefox 中没问题。

window.onbeforeunload = function() {
var result = confirm('Really?');

if(result) {
console.log('Do something');
}
}

有什么想法吗?谢谢!

最佳答案

您应该从 beforeunload 返回一些内容。

确认将被忽略

Since 25 May 2011, the HTML5 specification states that calls to window.showModalDialog(), window.alert(), window.confirm() and window.prompt() methods may be ignored during this event.

see MDN

window.onbeforeunload = function() {
return 'Date will be lost: are you sure?'; //<= here
}

如果您不返回某些内容,则处理程序函数中的操作将在页面卸载之前执行。

关于javascript - JavaScript 返回确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14139035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com