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 capture event when user is closing the Browser [modified]

How to capture event when user is closing the Browser [modified]

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
4 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 shopping cart site. I am storing products choosing in the session. How can i help me to capture event when user clicks the Close button (X button on the right top) to exit the Browser. Thank in advance vtkiet05

    A 1 Reply Last reply
    0
    • M mangrovecm

      I have a shopping cart site. I am storing products choosing in the session. How can i help me to capture event when user clicks the Close button (X button on the right top) to exit the Browser. Thank in advance vtkiet05

      A Offline
      A Offline
      Aleksandr71
      wrote on last edited by
      #2

      You can use onunload event of javascript. Something like this Good Luck.

      M 1 Reply Last reply
      0
      • A Aleksandr71

        You can use onunload event of javascript. Something like this Good Luck.

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

        Thank you for reply. Your code will always display message whenever the page closed. That mean user has still not close Browser, they click other items on page the message display too. Actually, I only confirm to user if they clicked Close Button (X buton on the right top ) Thank all your help vtkiet05 -- modified at 0:33 Wednesday 4th July, 2007

        M 1 Reply Last reply
        0
        • M mangrovecm

          Thank you for reply. Your code will always display message whenever the page closed. That mean user has still not close Browser, they click other items on page the message display too. Actually, I only confirm to user if they clicked Close Button (X buton on the right top ) Thank all your help vtkiet05 -- modified at 0:33 Wednesday 4th July, 2007

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

          >>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. :)

          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