JavaScript代码无法在Firefox for ASPX网站上运行

时间:2017-06-29 18:06:55

标签: 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 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;
    });
});

0 个答案:

没有答案