Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Confirm dialog with OK ,CANCEL buttons on window close

Confirm dialog with OK ,CANCEL buttons on window close

Scheduled Pinned Locked Moved JavaScript
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    siva455
    wrote on last edited by
    #1

    Hi, i have an popup which is an aspx page and when i click on browser close button..., the system should check if there is any unsaved data in the form or not. If there is any unsaved data then the message should be displayed (Do you want to leave..?) with OK and Cancel button... On click of the OK button, the data should not be saved and the user should be returned parent form ie popup should be closed and return to the parent form.On click of the cancel button, the control should return to the Pop. I had tried the below code... window.onbeforeunload = close; function close() { var result=confirm("Do you really want to close this window"); if (result) { return true; } else { location.href = document.URL; } } The above code is not working ie the popup is getting closed even on click of closse button.... and when clicked on OK it is dispalying another msgbox with leave this page and Stay on this page buttons... Please help me regarding the same...

    P 1 Reply Last reply
    0
    • S siva455

      Hi, i have an popup which is an aspx page and when i click on browser close button..., the system should check if there is any unsaved data in the form or not. If there is any unsaved data then the message should be displayed (Do you want to leave..?) with OK and Cancel button... On click of the OK button, the data should not be saved and the user should be returned parent form ie popup should be closed and return to the parent form.On click of the cancel button, the control should return to the Pop. I had tried the below code... window.onbeforeunload = close; function close() { var result=confirm("Do you really want to close this window"); if (result) { return true; } else { location.href = document.URL; } } The above code is not working ie the popup is getting closed even on click of closse button.... and when clicked on OK it is dispalying another msgbox with leave this page and Stay on this page buttons... Please help me regarding the same...

      P Offline
      P Offline
      phome
      wrote on last edited by
      #2

      I wish the following may solve u issue.

      function close() {

      var flgDataUnsaved = false;
      // do your unsave data check here
      
      
      // if there are unsaved data set flgDataUnsaved = true;
      if ( flgDataUnsaved ){
      	event.returnValue = "Do you really want to close this window";
      }else{
      	event.returnValue = true;
      }
      

      }
      window.onbeforeunload = close;

      and u can put a "save" button on your popup page. The user can save the data themselves.

      Good day,Good job,Good life

      L 1 Reply Last reply
      0
      • P phome

        I wish the following may solve u issue.

        function close() {

        var flgDataUnsaved = false;
        // do your unsave data check here
        
        
        // if there are unsaved data set flgDataUnsaved = true;
        if ( flgDataUnsaved ){
        	event.returnValue = "Do you really want to close this window";
        }else{
        	event.returnValue = true;
        }
        

        }
        window.onbeforeunload = close;

        and u can put a "save" button on your popup page. The user can save the data themselves.

        Good day,Good job,Good life

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I believe this line

        event.returnValue = "Do you really want to close this window";

        should be

        event.returnValue = confirm("Do you really want to close this window");

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups