Click here to Skip to main content
15,883,938 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my application, I have a menu in master page. The application asks for confirmation if the user is working on a Page and navigates to other screen/page without saving. It should show confirm msg like 'Do you want to leave this page without saving?' Are there any possiblities to do this?
Posted
Updated 31-Mar-22 10:17am
v2

Try this:
JavaScript
<script type="text/javascript">
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    return "Do you want to leave this page without saving?";
  }
 
Share this answer
 
v2
Use this
------------



XML
<script type="text/javascript" language="javascript">
               window.onbeforeunload = function() {
                   var Ans = confirm("Are you sure you want change page!");
                   if(Ans==true)
                       return true;
                   else
                       return false;
               };
    </script>
 
Share this answer
 
Comments
GrpSMK 3-May-17 2:35am    
how to display this pop up only while textbox(in menu page) containing some text..and suddenly navigate pages.
You can do this jquery. This is the perfect example you can refer for your query.

http://api.jquery.com/unload/[^]

If you want to do this on button click event you can refer this.
http://myclabs.github.io/jquery.confirm/

http://www.projectshadowlight.org/jquery-easy-confirm-dialog/[^]
 
Share this answer
 
v3
window.onbeforeunload = function() {
            return 'Are you sure you want to leave this page?';
            };
 
Share this answer
 
v2
Comments
Richard Deeming 27-Feb-18 11:59am    
As posted in solution #3 - FOUR YEARS AGO.
Member 14705531 9-Feb-20 13:34pm    
Submitted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900