2013-07-24 64 views
5

我正在使用下面的代码来离开当前页面。 它在Chrome和Mozilla中运行良好,但它在IE 10浏览器中调用每个锚定标记。 如何防止在IE 10浏览器中调用此功能?IE浏览器中的onbeforeunload问题

window.onbeforeunload = function() 
{ 
    return ""; 
}; 
+0

这似乎是一个合理的问题,想知道为什么它被选为被关闭 –

回答

1

这是IE浏览器的默认行为,则需要从锚标记删除onbeforeunload事件,而你是盘旋在它:

$(document).ready(function(){ 
    //store onbeforeunload for later use 
    $(window).data('beforeunload',window.onbeforeunload); 

     //remove||re-assign onbeforeunload on hover 
    $('a') 
     .hover( 
      function(){window.onbeforeunload=null;}, 
      function(){window.onbeforeunload=$(window).data('beforeunload');} 
      ); 


}); 

,或者您需要“返回false”每个锚的onClick事件标签:

​​
+0

我用上面的代码仍然的onclick锚标记再次将caliing onbefore卸载 – shivakumar

+0

更改$('a')!!!现在检查 –

+0

仍然无法正常工作某些人可以用我的上面的代码给我确切的解决方案 – shivakumar

0

使用此

window.onbeforeunload = function (e) { 
var e = e || window.event; 

// For IE and Firefox 
if (e) { 
    e.returnValue = ''; 
} 

// For Chrome and Safari 
return ''; 
}; 
0

试试这个

<html> 
<head> 
<script> 
    function closeIt() 
    { 
     return "Any string value here forces a dialog box to \n" + 
    "appear before closing the window."; 
    } 
    window.onbeforeunload = closeIt; 
</script> 
</head>