How can I prevent [removed] from being triggered by [removed] href links in IE?

前端 未结 6 1667
清酒与你
清酒与你 2021-01-30 05:24

I\'m building a fail safe for my form that is going to warn users that if they leave the page their form data will be lost (similar to what gmail does).

window.         


        
6条回答
  •  深忆病人
    2021-01-30 06:03

    You may remove and re-assign the onbeforeunload when hovering those links:

    jQuery(
      function($)
      {
          //store onbeforeunload for later use
        $(window).data('beforeunload',window.onbeforeunload);  
    
          //remove||re-assign onbeforeunload on hover 
        $('a[href^="javascript:"]')
          .hover( 
                 function(){window.onbeforeunload=null;},
                 function(){window.onbeforeunload=$(window).data('beforeunload');}
                );
    
      }
    );
    

提交回复
热议问题