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. Detect Browser Close

Detect Browser Close

Scheduled Pinned Locked Moved ASP.NET
csharpjavascript
5 Posts 2 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
    MaheshSharma
    wrote on last edited by
    #1

    I want to clear a session by calling an assembly, How i deduct browser close button in javascript or vb.net. When the user click on the close button of browser i want to call a method in code behind. Thanks Mahesh

    M 1 Reply Last reply
    0
    • M MaheshSharma

      I want to clear a session by calling an assembly, How i deduct browser close button in javascript or vb.net. When the user click on the close button of browser i want to call a method in code behind. Thanks Mahesh

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

      Detecting browser unload event. - Use onunload event of body tag to detect the closing of browser. Calling Server-side function from client-side script - Add a server-side hiddenfield to your page. - Write the code (eg: clearing a session) in the change event of this hiddenfield. - Grab this field and put some value to this hidden field from Javascript. As soon as the value is changed in this hiddenfield, the server-side event will be fired/invoked so that the code for clearing a session will be run. Hope it would help.. Let me know if you are not clear.

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

      M 1 Reply Last reply
      0
      • M Michael Sync

        Detecting browser unload event. - Use onunload event of body tag to detect the closing of browser. Calling Server-side function from client-side script - Add a server-side hiddenfield to your page. - Write the code (eg: clearing a session) in the change event of this hiddenfield. - Grab this field and put some value to this hidden field from Javascript. As soon as the value is changed in this hiddenfield, the server-side event will be fired/invoked so that the code for clearing a session will be run. Hope it would help.. Let me know if you are not clear.

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

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

        Michael, Thanks for reply. Well i write a function in javascript and call that function like that from inside the body tag onunload ="CloseBrow();" inside the CloseBrow how i detect when user click on Close button of browser, i must have to check that since page is unloaded every time when user move back and forth. I user some script inside that function "if (screenTop > 9999)" but this is working in some browser and not working in another browser. thanks and regards mahesh

        M 1 Reply Last reply
        0
        • M MaheshSharma

          Michael, Thanks for reply. Well i write a function in javascript and call that function like that from inside the body tag onunload ="CloseBrow();" inside the CloseBrow how i detect when user click on Close button of browser, i must have to check that since page is unloaded every time when user move back and forth. I user some script inside that function "if (screenTop > 9999)" but this is working in some browser and not working in another browser. thanks and regards mahesh

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

          Yeah. You are right.. Have you tried this?

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

          M 1 Reply Last reply
          0
          • M Michael Sync

            Yeah. You are right.. Have you tried this?

            Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

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

            Yes I tried it. I tried this one also if (window.event.clientX < 0 || window.event.clientY < 0) This is working for IE in some machine and not for others. And I place a html button runat="server" whose display style is none after check this if (window.event.clientX < 0 || window.event.clientY < 0) i fired the button click from javascript and call a procedure in code behind, like that window.document.hidBut.click(); Pls let me know if there is another way to handle the close button of browser. regards mahesh

            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