Javascript 页面卸载事件在IE 9,10中不工作
如果用户单击后退按钮/按F5/尝试重新加载页面,我将尝试向用户发出警报。 我正在使用下面的脚本Javascript 页面卸载事件在IE 9,10中不工作,javascript,asp.net,internet-explorer,onbeforeunload,Javascript,Asp.net,Internet Explorer,Onbeforeunload,如果用户单击后退按钮/按F5/尝试重新加载页面,我将尝试向用户发出警报。 我正在使用下面的脚本 <script type="text/javascript"> var testEvent = window.attachEvent || window.addEventListener; var checkEvent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; testEvent (checkEvent , fu
<script type="text/javascript">
var testEvent = window.attachEvent || window.addEventListener;
var checkEvent = window.attachEvent ? 'onbeforeunload' : 'beforeunload';
testEvent (checkEvent , function (e) {
console.log(e);
var hdnCountValue= $("#" + '<%=hdnCount.ClientID %>').val();
console.log(hdnCountValue);
if (hdnCountValue!= null && hdnCountValue!= "" && hdnCountValue!= 'undefined' && parseInt(hdnCountValue) > 0) {
var msg = 'Warning: You will lose all your data.';
(e || window.event).returnValue = msg ;
return msg;
}
});
</script>
var testEvent=window.attachEvent | | window.addEventListener;
var checkEvent=window.attachEvent?'onbeforeunload':'beforeunload';
testEvent(检查事件,函数(e){
控制台日志(e);
var hdnCountValue=$(“#“+”).val();
console.log(hdnCountValue);
如果(hdnCountValue!=null&&hdnCountValue!=“”&&hdnCountValue!='undefined'&&parseInt(hdnCountValue)>0){
var msg='警告:您将丢失所有数据';
(e | | window.event).returnValue=msg;
返回味精;
}
});
它在Firefox和chrome中运行良好
但在IE9和IE10中,它有时有效,有时无效。
在safari中也可以,但当用户选择停留在页面上时,它会更改URL,并显示上一页的URL