onbeforeunload替代Chrome [英] onbeforeunload alternative for Chrome
问题描述
是否有任何替代windows.onbeforeunload for Chrome.It在IE中工作正常但不在chrome中,这是我的代码..
window.onbeforeunload = CloseSession;
函数CloseSession(){
//如果浏览器关闭则从需求中注销用户如果(((window.event.clientY< 0)&&(window.event.clientX> 40))
按下或按下alt + f4不用于后退按钮
||(event.altKey == true && event.keyCode == 0))
window.open('LogOffUser.aspx','_ parent','left = 9999,top = 9999,width = 1px,height = 1px');
}
Is there any alternative for window.onbeforeunload for Chrome.It working fine in IE but not in chrome,here is my code..
window.onbeforeunload = CloseSession;
function CloseSession() {
//log out the user from demand if browser close or alt+f4 is pressed not for backbutton
if (((window.event.clientY < 0) && (window.event.clientX > 40))
||(event.altKey == true && event.keyCode == 0))
window.open('LogOffUser.aspx', '_parent', 'left = 9999, top = 9999,width=1px, height=1px');
}
推荐答案
这是我用来设置onbeforeunload事件的代码,它可以工作对于Chrome。
它写的顺序是至关重要的,否则它不会起作用。
This is the code that I used to set the onbeforeunload event and it works for Chrome.
The order it was written is crucial though else it wouldnt work.
<script>
var unloadEvent = function (e) {
var confirmationMessage = "Warning: Leaving this page will result in any unsaved data being lost. Are you sure you wish to continue?";
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Webkit, Safari, Chrome etc.
};
window.addEventListener("beforeunload", unloadEvent);
</script>
这篇关于onbeforeunload替代Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!