当用户从浏览器关闭时如何处理显示meesage [英] how to handle show a meesage when users close from browser

查看:99
本文介绍了当用户从浏览器关闭时如何处理显示meesage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨所有

i希望在关闭浏览器窗口后向用户显示提醒。



您可以说使用卸载或onunload事件

但是点击我的表单中的提交按钮时会触发此事件

并在提交表单时向他们显示此警告!!!!!

i想要在浏览器附近显示提醒。

我该怎么做

感谢您的帮助

hi to all
i want to show a alert to users after close browser window.

you may say that use of unload or onunload event
but this event fire when my submit button in my form is clicked
and this alert show to them when form is submitted!!!!!
i want to show alert just close from browser.
how can i do this
thanks for any help

推荐答案

you can use following script as 







var confirmOnPageExit = function (e) {
     // If we haven't been passed the event get the window.event
     e = e || window.event;

     var message = 'Your information will be lost. Are you sure ?';

     // For IE6-8 and Firefox prior to version 4
     if (e) {
         e.returnValue = message;
     }

     // For Chrome, Safari, IE8+ and Opera 12+
     return message;
 };


 // Turn it on - assign the function that returns the string
 window.onbeforeunload = confirmOnPageExit;










DeActivate on Submit button







<input type="submit" onclick="window.onbeforeunload = null; " value="Save"  />

< br $> b $ b






For the new changes in input fields








' input')。blur( function (){

window .onbeforeunload = confirmOnPageExit;
});
('input').blur(function () { window.onbeforeunload = confirmOnPageExit; });


这篇关于当用户从浏览器关闭时如何处理显示meesage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆