beforeunload 窗口显示两个对话框
我有这个 jQuery 代码;
$(function () {
$(window).unbind("beforeunload");
$(window).bind("beforeunload", function () {
return confirm("Really?");
});
});
当我关闭窗口时,我会收到确认请求,如果我点击“取消”,我会收到第二次确认,其中显示:
“您确定要离开此页面吗?”
“假”
“按“确定”继续,或按“取消”留在当前页面。”
为什么我会出现第二个对话框?有办法将其删除吗?
编辑
已将代码更改为;
$(function () {
$(window).bind("beforeunload", function () {
return "slappy?";
});
});
但没有出现确认消息。该事件正在触发,因为我可以在其中放置警报并查看警报。
编辑2
已将代码更改为:
window.onbeforeunload = function () {
var txtBlog = $('#tbxNote').val();
if (txtBlog != "")
return "You have not saved your blog entry.";
}
它有效,但我的消息上方和下方还有其他文字;
“您确定要离开此页面吗?”
“您尚未保存您的博客条目。”
“按“确定”继续,或按“取消”留在当前页面。”
I have this jQuery code;
$(function () {
$(window).unbind("beforeunload");
$(window).bind("beforeunload", function () {
return confirm("Really?");
});
});
When i close my window I get the confirmation request and if I hit "Cancel" I get a second confirmation which says;
"Are you sure you want to navigate away from this page?"
"False"
"Press OK to continue, or Cancel to stay on the current page."
Why am I getting a second dialog and is there a way to remove it?
edit
have changed the code to be;
$(function () {
$(window).bind("beforeunload", function () {
return "slappy?";
});
});
But the confirmation message does not appear. The event is firing because I can put an alert in there and see the alert.
edit 2
Have changed the code to this;
window.onbeforeunload = function () {
var txtBlog = $('#tbxNote').val();
if (txtBlog != "")
return "You have not saved your blog entry.";
}
it works but there is other text above and below my message;
"Are you sure you want to navigate away from this page?"
"You have not saved your blog entry."
"Press OK to continue, or Cancel to stay on the current page."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用:
beforeunload 事件要求您返回一个字符串,其中包含您想要在标准“您确定”对话框中显示的消息。
Just use:
The beforeunload event requires you to return a string containing the message you want displayed in the standard "Are you sure" dialog.