ASP.NET, jQuery, dirty forms, and [removed]

前端 未结 5 2102
抹茶落季
抹茶落季 2020-12-16 17:07

In my ASP.NET web app, I\'m trying to create a universal way of warning users before navigating away from a form when they\'ve made changes, using jQuery. Pretty standard st

5条回答
  •  星月不相逢
    2020-12-16 17:30

    Got this to work by basically tracking the mouse position. Keep in mind you can still get positive values to your Y value (hence my < 50 line of code), but as long as your submit buttons are more than 100 pixels down you should be fine.

    Here is the Javascript I added to track mouse changes and capture the onbeforeunload event:

        
    
    
        
    

    Then just add the following form onto your page:

        

    And that's it! It could use a little cleanup (remove the MouseX, etc), but this worked in my existing ASP.net 3.5 application and thought I would post to help anyone out. Works in IE 7 and Firefox 3.6, haven't tried Chrome yet.

提交回复
热议问题