【发布时间】:2011-01-26 11:08:14
【问题描述】:
大家好,如果用户单击返回按钮,我正在使用 window.onbeforeunload 向用户显示一个 javascript 对话框来处理。 我的代码工作到一定程度,但如果用户单击“离开此页面”,我很难重定向用户(消息在不同的浏览器中有所不同)。
// Set check var false to begin with
// This is set true on submit btns using onclick event
submitFormOkay = false;
// If we are on check-availability page
if( window.location.href.indexOf( 'check-availability' ) != -1 )
{
// If back button is clicked
window.onbeforeunload = function()
{
// Only show dialog if submit btn wasn't clicked
if (!submitFormOkay)
{
// Show dialog
return "Use of the browser back button will lose form data.\nPlease use the 'Previous' button at the bottom of the form.";
// If 'leave' this page was clicked'
// do 'window.location = window.location'
}
}
}
提前致谢。
大卫
【问题讨论】:
标签: javascript