日期:2014-05-16 浏览次数:20398 次
window.onunload = function unLoad( e ) { if (window.event) { // IE browser, could work e = window.event; if (e.clientY < 0 || e.ctrlKey) { // Handle two scenarios: click the x button of the tab or press Ctrl + F4 logout(); } } else if (window.event) { // Safari if (document.documentElement.scrollWidth == 0) { logout(); // Couldn't send the request to the server when unload event occurred in Safari } } else { // Firefox, could listen to the event, but couldn’t send the logout() request to server if (document.documentElement.scrollWidth == 0) { // Alternatively, if we choose the window.onbeforeunload event, which could be triggered by refreshing the window or navigating to another page or closing the tab. This condition would never happen despite we could send the logout() request to server logout(); } } }