|
|
#1 (permalink) |
|
after g, before i
Resident.
Joined in Jul 2004
Lives in N,BC,CA
8,033 posts
Gave thanks: 48
Thanked 129 times
|
AJAX on page close/leave
Has anyone ever done anything that involved executing code when someone either closes or leaves a page? Meaning some closes a tab, clicks a link, etc...
Just curious as to how you handled it. I'm looking at using window.onunload and sending a SJAX (intentional spelling) request when someone leaves to track some analytics stuff. Only problem is I'm finding browser support various greatly to the point it's pretty much unreliable. Any suggestions? |
|
|
|
|
|
#2 (permalink) |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,542 posts
Gave thanks: 91
Thanked 49 times
|
Browser support is always a victim to use all in the world of scripting....
I'd say, as long as it works with IE and FireFox, then all should be fine. I could do some searching if needed, but generally, it doesnt have to be ajax, but just pure javascript. Be careful with this implementation, it could cause frustration with your visitors : /
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
#3 (permalink) |
|
after g, before i
Resident.
Joined in Jul 2004
Lives in N,BC,CA
8,033 posts
Gave thanks: 48
Thanked 129 times
|
I don't think you quite get what we're doing. We're sending a silent request behind the scenes when the visitor closes the page. They shouldn't have a clue it's going on unless they're watching for it through an XHR console.
I have a feeling we won't go with this route just due to lack of support. From testing, IE supports about half the closing events I could think of (eg: closing tab, typing in a new URL, etc...), Firefox supports almost all, Safari supports almost all, and Opera supported like one. |
|
|
|
|
|
#4 (permalink) |
|
Surpass Fan
Comfy Contributor
Joined in Oct 2004
148 posts
Gave thanks: 2
Thanked 2 times
|
We use onunload to terminate user session. It works well but officially we support only IE6/7 so no cross browser issues for us :-)
__________________
David Kaspar | SH60 |
|
|
|
|
|
#6 (permalink) |
|
Surpass Fan
Comfy Contributor
Joined in Oct 2004
148 posts
Gave thanks: 2
Thanked 2 times
|
Just did a quick test in IE7:
Closing tab: yes Closing browser: yes Typing in an URL: yes Clicking on a bookmark: yes FireFox 2 Closing tab: yes Closing browser: yes Typing in an URL: yes Clicking on a bookmark: SOMETIMES Did not test in Safari for Windows ;-)
__________________
David Kaspar | SH60 Last edited by davotoula; June 12th, 2007 at 1:54 PM. |
|
|
|
|
|
#8 (permalink) |
|
L'Awesome Advocate
Super #1
Joined in May 2004
Lives in .au
Hosted on Mango
2,423 posts
Gave thanks: 1
Thanked 5 times
|
If you'd like a test on Safari on Mac OS X, then post a link & I'll be glad to do so.
__________________
When I get sad, I stop being sad, and be AWESOME instead. True story.
|
|
|
|