Click here to Skip to main content
15,914,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Need confirmation message only while closing window or user click on back button not while user refresh the page

thank you in advance......
Posted
Comments
Prasad_Kulkarni 2-May-12 6:13am    
can you post some code snippets?
Raj7sam 2-May-12 6:16am    
i need just javascript code that will not ask confirmation on refreshing page
it will ask confirmation only when user try to close the window or clicks back button i don't have code snippet trying fresh ...i googled also but didn't get the answer
Raj7sam 2-May-12 6:17am    
please help in this...

hi,

add this script to your aspx page and test

HTML
<script language="JavaScript">
      var needToConfirm = true;

      window.onbeforeunload = confirmExit;
      function confirmExit() {
          if (needToConfirm)
              return "Are you sure to leave this page?";
      }
  </script>


hope this help you.
 
Share this answer
 
Comments
Raj7sam 2-May-12 9:32am    
Hi it is asking confirmation while closing the window or user clicks on back button in window and for refresh also it is asking confirmation, but here only while refreshing i dont want this confirmation.
Hi it is asking confirmation while closing the window or user clicks on back button in window and for refresh also it is asking confirmation, but here only while refreshing i dont want this confirmation.
 
Share this answer
 
any one please give the solution i tried every thing but not getting this issue solved

thanx in advacned
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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