Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

.NET script to detect browser close event?, .net / javascript

views
     
TSragk
post Sep 29 2015, 05:57 PM, updated 9y ago

BooBoo~
*******
Senior Member
2,265 posts

Joined: Apr 2009


Hi, any1 knew how to detect a browser closing event?
I have a session storing a collection of Data Table (for my services to do their work), i wanted to remove specify session when user close the tab/browser to avoid the session getting bigger and heavier, any good idea to achieve that? Have been playing with this whole day with body onunload / onbeforeunload event but nothing worked.

This post has been edited by ragk: Sep 29 2015, 05:57 PM
anangryorc
post Sep 29 2015, 09:38 PM

On my way
****
Senior Member
597 posts

Joined: May 2006


https://developer.mozilla.org/en-US/docs/We.../onbeforeunload

window.onbeforeunload
TSragk
post Sep 30 2015, 11:19 AM

BooBoo~
*******
Senior Member
2,265 posts

Joined: Apr 2009


QUOTE(anangryorc @ Sep 29 2015, 09:38 PM)
doesn't work :-/
alien3d
post Sep 30 2015, 11:25 AM

Look at all my stars!!
*******
Senior Member
3,740 posts

Joined: Mar 2009
QUOTE(ragk @ Sep 29 2015, 05:57 PM)
Hi, any1 knew how to detect a browser closing event?
I have a session storing a collection of Data Table (for my services to do their work), i wanted to remove specify session when user close the tab/browser to avoid the session getting bigger and heavier, any good idea to achieve that? Have been playing with this whole day with body onunload / onbeforeunload event but nothing worked.
*
you shouldn't worried about it unless you big as facebook.. a few kb okay la.
TSragk
post Sep 30 2015, 02:52 PM

BooBoo~
*******
Senior Member
2,265 posts

Joined: Apr 2009


QUOTE(alien3d @ Sep 30 2015, 11:25 AM)
you shouldn't worried about it unless you big as facebook.. a few kb okay la.
*
yeah seems like only can give up on this, tested many methods doesn't work, and the function might fade away when browser updated

anangryorc
post Sep 30 2015, 06:35 PM

On my way
****
Senior Member
597 posts

Joined: May 2006


CODE
window.onbeforeunload = function (e) {
return 'exiting...';


Tested on chrome and ie11 its working.

http://jsfiddle.net/0rxsz76o/

This post has been edited by anangryorc: Sep 30 2015, 06:49 PM
TSragk
post Sep 30 2015, 09:55 PM

BooBoo~
*******
Senior Member
2,265 posts

Joined: Apr 2009


QUOTE(anangryorc @ Sep 30 2015, 06:35 PM)
CODE
window.onbeforeunload = function (e) {
return 'exiting...';


Tested on chrome and ie11 its working.

http://jsfiddle.net/0rxsz76o/
*
hmmm, maybe something doesnt cope well in my script, i will check around again, thanks !
jurkflash
post Oct 12 2015, 10:31 PM

Getting Started
**
Junior Member
95 posts

Joined: Sep 2010
QUOTE(ragk @ Sep 29 2015, 05:57 PM)
Hi, any1 knew how to detect a browser closing event?
I have a session storing a collection of Data Table (for my services to do their work), i wanted to remove specify session when user close the tab/browser to avoid the session getting bigger and heavier, any good idea to achieve that? Have been playing with this whole day with body onunload / onbeforeunload event but nothing worked.
*
Practically no ways for server to know is client closed the browser..
But u can attempt below..
Javascript interval every few seconds post to a webservice, if no response coming back then u can kill off the session
With all those code and time trial, i suggest avoid all these, store only needed stuff into the session and let it expire itself

 

Change to:
| Lo-Fi Version
0.0138sec    0.21    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 07:23 PM