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. ASP.NET
  4. How to display a message when user is closing the Browser

How to display a message when user is closing the Browser

Scheduled Pinned Locked Moved ASP.NET
helptutorial
9 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.
  • M Offline
    M Offline
    mangrovecm
    wrote on last edited by
    #1

    I have a code: var UNLOAD_MSG = "You will lose any unsaved changes!"; var IGNORE_UNLOAD = true; function doBeforeUnload() { if(IGNORE_UNLOAD) return; // Let the page unload if(window.event) window.event.returnValue = UNLOAD_MSG; // IE else return UNLOAD_MSG; // FX } if(window.body) window.body.onbeforeunload = doBeforeUnload; // IE else window.onbeforeunload = doBeforeUnload; // FX function CheckOrder(isChanges) { IGNORE_UNLOAD = isChanges; }

    The code above will confirm user whenever they try to exit a page if value of GetStatus() function is 'false'. Actually problem the user has still not exit browser, they link to other pages in the website but they always receive the message "You will lose any unsaved changes!". So I only want display a message when user is closing the Browser (Click "X" button). Thank in advance.

    vtkiet05

    M 1 Reply Last reply
    0
    • M mangrovecm

      I have a code: var UNLOAD_MSG = "You will lose any unsaved changes!"; var IGNORE_UNLOAD = true; function doBeforeUnload() { if(IGNORE_UNLOAD) return; // Let the page unload if(window.event) window.event.returnValue = UNLOAD_MSG; // IE else return UNLOAD_MSG; // FX } if(window.body) window.body.onbeforeunload = doBeforeUnload; // IE else window.onbeforeunload = doBeforeUnload; // FX function CheckOrder(isChanges) { IGNORE_UNLOAD = isChanges; }

      The code above will confirm user whenever they try to exit a page if value of GetStatus() function is 'false'. Actually problem the user has still not exit browser, they link to other pages in the website but they always receive the message "You will lose any unsaved changes!". So I only want display a message when user is closing the Browser (Click "X" button). Thank in advance.

      vtkiet05

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      I dont think it can be done like that .. all you can do is that you may need to set the statas "IGNORE_UNLOAD" to true manually in each and every click event of "A" tags.

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

      M 1 Reply Last reply
      0
      • M Michael Sync

        I dont think it can be done like that .. all you can do is that you may need to set the statas "IGNORE_UNLOAD" to true manually in each and every click event of "A" tags.

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

        M Offline
        M Offline
        mangrovecm
        wrote on last edited by
        #3

        Thanks Michael for your reply. My exactly problem here is that I can't catch exactly the event when I click X button to close a browser. I tried to use unload event, but the big issue happened. Closing a browser and linking to other page are unload event, so the message always displays when i do both actions. I really want to catch the closing browser event(click on X button) only. Please send me any your solutions. Thanks for all help. vtkiet05

        M 1 Reply Last reply
        0
        • M mangrovecm

          Thanks Michael for your reply. My exactly problem here is that I can't catch exactly the event when I click X button to close a browser. I tried to use unload event, but the big issue happened. Closing a browser and linking to other page are unload event, so the message always displays when i do both actions. I really want to catch the closing browser event(click on X button) only. Please send me any your solutions. Thanks for all help. vtkiet05

          M Offline
          M Offline
          Michael Sync
          wrote on last edited by
          #4

          try "onunload" event of body.. I hav tested ur sample. it shows the msg when i click "x" button of your browser..

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

          M 1 Reply Last reply
          0
          • M Michael Sync

            try "onunload" event of body.. I hav tested ur sample. it shows the msg when i click "x" button of your browser..

            Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

            M Offline
            M Offline
            mangrovecm
            wrote on last edited by
            #5

            Thank for your reply, Could you test the case which you link to other page? I think that the message will displays. I don't want to display a message this case. I would like to display a message if user clicked Close Button (X button on the right top) Thank all your helps vtkiet05

            N 1 Reply Last reply
            0
            • M mangrovecm

              Thank for your reply, Could you test the case which you link to other page? I think that the message will displays. I don't want to display a message this case. I would like to display a message if user clicked Close Button (X button on the right top) Thank all your helps vtkiet05

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #6

              vtkiet05@hotmail.com wrote:

              I don't want to display a message this case. I would like to display a message if user clicked Close Button

              What do you want to do ? Display confirmation message when user closing browser window ?


              Navaneeth My Website | Ask smart questions

              M 1 Reply Last reply
              0
              • N N a v a n e e t h

                vtkiet05@hotmail.com wrote:

                I don't want to display a message this case. I would like to display a message if user clicked Close Button

                What do you want to do ? Display confirmation message when user closing browser window ?


                Navaneeth My Website | Ask smart questions

                M Offline
                M Offline
                mangrovecm
                wrote on last edited by
                #7

                Yes, Can you help me do that? I can display confirmation message when user closing browser window now. But if i link to other page, the message also displays. Could you help me display confirmation message when user closing browser window? Thank in advance vtkiet05

                M 1 Reply Last reply
                0
                • M mangrovecm

                  Yes, Can you help me do that? I can display confirmation message when user closing browser window now. But if i link to other page, the message also displays. Could you help me display confirmation message when user closing browser window? Thank in advance vtkiet05

                  M Offline
                  M Offline
                  Michael Sync
                  wrote on last edited by
                  #8

                  >>Thank for your reply, Could you test the case which you link to other page? >>I think that the message will displays. I don't want to display a message >>this case. I would like to display a message if user clicked Close Button (X >>button on the right top) >>Thank all your helps chk it out. hope it would help.. var UNLOAD_MSG = "You will lose any unsaved changes!"; var IGNORE_UNLOAD = true; function doBeforeUnload() { if(IGNORE_UNLOAD) return; // Let the page unload if(window.event) window.event.returnValue = UNLOAD_MSG; // IE else return UNLOAD_MSG; // FX } if(window.body) window.body.onbeforeunload = doBeforeUnload; // IE else window.onbeforeunload = doBeforeUnload; // FX function CheckOrder(isChanges) { IGNORE_UNLOAD = isChanges; } [mike](http://michaelsync.net) Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :) Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

                  M 1 Reply Last reply
                  0
                  • M Michael Sync

                    >>Thank for your reply, Could you test the case which you link to other page? >>I think that the message will displays. I don't want to display a message >>this case. I would like to display a message if user clicked Close Button (X >>button on the right top) >>Thank all your helps chk it out. hope it would help.. var UNLOAD_MSG = "You will lose any unsaved changes!"; var IGNORE_UNLOAD = true; function doBeforeUnload() { if(IGNORE_UNLOAD) return; // Let the page unload if(window.event) window.event.returnValue = UNLOAD_MSG; // IE else return UNLOAD_MSG; // FX } if(window.body) window.body.onbeforeunload = doBeforeUnload; // IE else window.onbeforeunload = doBeforeUnload; // FX function CheckOrder(isChanges) { IGNORE_UNLOAD = isChanges; } [mike](http://michaelsync.net) Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :) Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

                    M Offline
                    M Offline
                    mangrovecm
                    wrote on last edited by
                    #9

                    Very good. Thank you very much!!! vtkiet05

                    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