Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 页面卸载事件在IE 9,10中不工作_Javascript_Asp.net_Internet Explorer_Onbeforeunload - Fatal编程技术网

Javascript 页面卸载事件在IE 9,10中不工作

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

如果用户单击后退按钮/按F5/尝试重新加载页面,我将尝试向用户发出警报。 我正在使用下面的脚本

<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