在chrome上显示类似于关闭窗口时的firefox的警报消息.确认消息”;离开"或“;留在这个页面上&quo
Show alert message on chrome similar to firefox on window close.Confirmation message "Leave" or "Stay on this page" not required
我想在网页窗口关闭前显示一条警告消息。以下代码适用于firefox和IE,但在chrome和safari上没有显示警报消息。
**window.onbeforeunload=uEvent;
function uEvent()
{
alert("you are being logged out");
}**
对于铬,我尝试使用return"您正在被注销";代替警报消息,但此警报消息为用户提供了"离开此页面"或"留在此页面"的选项,这在我的情况下是不希望的请帮我一下,这样chrome和safari也有类似的行为,比如firefox和IE
感谢Youri Arkesteijn
,您可以使用以下代码:
var dont_confirm_leave = 0; //set dont_confirm_leave to 1 when you want the user to be able to leave withou confirmation
var leave_message = 'You sure you want to leave?'
function goodbye(e)
{
if(dont_confirm_leave!==1)
{
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = leave_message;
//e.stopPropagation works in Firefox.
if (e.stopPropagation)
{
e.stopPropagation();
e.preventDefault();
}
//return works for Chrome and Safari
return leave_message;
}
}
window.onbeforeunload=goodbye;
你可以看到这个问题。。。关于stackoverflow
我在chrome
、I.E
和Mozila
中检查了这个。。。
相关文章:
- Ajax聊天消息重复而不仅仅是更新
- 铬:“;未捕获的语法错误:意外的标记:"
- 如果localstorage为空,则显示欢迎消息
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- "消息:应为')'"但事实并非如此;看起来不对
- IE 11没有显示“;显示内容"弹出消息
- 在chrome上显示类似于关闭窗口时的firefox的警报消息.确认消息”;离开"或“;留在这个页面上&quo
- 谷歌地图Api在CRM Dynamics 2011 iframe"不可能使用显示属性“;消息
- 避免“;无响应脚本"foreach循环中的消息
- playframework javascript资产JSLint处理:信息消息"x源上的Javascript
- "消息发送”;PHP和JS的确认弹出窗口
- "[仅报告]拒绝加载字体"控制台上的错误消息
- "无法读取属性'消息'未定义的“;在WebSQL错误回调中
- "执行insertHtml命令“”时出错;当在“”中插入html时,cleditor中的消息;查看源“;模式
- "JavaScript应用程序”;警报消息
- "加载“;JQM中页面底部生成的消息
- 如何显示“;已保存"执行Redirect()后的消息.
- "意外的输入结束“;从简单POST请求到node.js的响应消息
- "消息“:"无效的web服务调用,缺少参数u0027的值