JavaScript代码在Firefox for ASPX网站中不起作用
我有下面的JS代码,可以帮助从ASPX页面注销会话,以便将“注销”记录存储在数据库中。当使用IE11、EDGE和Chrome打开站点时,该代码起作用。使用这三种浏览器,用户会得到一个弹出窗口,询问是留在网站上还是离开网站。当它在Firefox(至少是54版)上进行测试时,它就是不起作用。什么也没出现 代码是:JavaScript代码在Firefox for ASPX网站中不起作用,javascript,asp.net,firefox,Javascript,Asp.net,Firefox,我有下面的JS代码,可以帮助从ASPX页面注销会话,以便将“注销”记录存储在数据库中。当使用IE11、EDGE和Chrome打开站点时,该代码起作用。使用这三种浏览器,用户会得到一个弹出窗口,询问是留在网站上还是离开网站。当它在Firefox(至少是54版)上进行测试时,它就是不起作用。什么也没出现 代码是: //We want to capture when a user logs out from the system - this is a way to force the browser
//We want to capture when a user logs out from the system - this is a way to force the browser to log out the session
window.onbeforeunload = closingCode;
function closingCode() {
// when user clicks the 'X' from the browser, will be prompted to leave or to stay
//clicking any of the options will trigger an event that will capture when the session was logged out and saved in the db
var button = document.getElementById('btnLogout');
button.click();
return "You are closing or refreshing this site. Clicking 'Stay on this page' will log out your session. Clicking 'Leave this page' will close your window.";
//return null;
}
//this will prevent the popup to appear everytime user navigates between pages/links
$(document).ready(function () {
$('a[rel!=ext]').click(function () {
window.onbeforeunload = null;
});
$('form').submit(function () {
window.onbeforeunload = null;
});
});
从“为了防止不必要的弹出窗口,一些浏览器不显示在beforeunload事件处理程序中创建的提示,除非该页面已与之交互;一些浏览器根本不显示它们。”浏览器兼容性表明Chrome、Firefox、Opera和Safari具有某种形式的此引用,但没有指定每个浏览器上的行为,可能FF只是阻止弹出窗口?也来自同一MDN页面“另外,请注意,各种浏览器忽略事件的结果,根本不要求用户确认。文档将始终自动卸载。Firefox在about:config中有一个名为dom.disable_beforeunload的开关以启用此行为。”