Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onbeforeunload issue in IE browser

Tags:

jquery

I am using below code for leaving the current page. It works fine in chrome and mozilla, but it is calling for every anchor tags in IE 10 browser. What can I do to prevent calling this in IE 10 browser?

window.onbeforeunload = function()
{   
   return  "";
};
like image 416
shivakumar Avatar asked Nov 02 '22 18:11

shivakumar


1 Answers

this is default behavior of IE, you need to remove onbeforeunload event from anchor tag while you are hovering over it:

$(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');}
            );


});

Or you need to 'return false' onClick event of each anchor tag:

<a onclick="someFunction(); return false;" href="lnk" >my link</a>
like image 192
Zaheer Ahmed Avatar answered Nov 30 '22 12:11

Zaheer Ahmed