我有一个聊天应用程序,我希望当用户意外关闭浏览器时,我想在窗口关闭之前给他一个jquery对话框警告,并执行必要的清理operations.Please帮助
发布于 2011-06-16 00:01:30
是的,下面的脚本使用了jQuery命名空间...
jQuery(window).bind('beforeunload', function(event) {
event.stopPropagation();
event.returnValue = "Attention !\nVous n'avez pas sauver vos paramètres.\nSi vous appuyer sur OK, vous perdrez les informations en cours d'utilisation...\n\nLa fenêtre est sur le point de se fermer";
return event.returnValue;
});发布于 2009-07-31 08:17:25
也许你将不得不使用window.onbeforeunload事件来获得它。
看看这个page
绑定到表单页面的用法示例
function setConfirmUnload(on) {
window.onbeforeunload = (on) ? unloadMessage : null;
}
function unloadMessage() {
return 'You have entered new data on this page. If you navigate away from this page without first saving your data, the changes will be lost.';
}
$(document).ready(function() {
$(':input',document.myForm).bind("change", function() { setConfirmUnload(true); }); // Prevent accidental navigation away
});发布于 2009-07-31 08:18:37
基本上,您最终使用的代码如下:
jQuery(window).unload(function(e) {
var chg = jQuery(".crayon-changed");
if (chg.length && uniConfirm(configCrayons.txt.sauvegarder)) {
chg.next().find('form').submit();
}
}); 这里的javascript代码的Here is a link (如我上面链接的线程所示)
https://stackoverflow.com/questions/1211257
复制相似问题