icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.
Old June 8th, 2007, 3:07 PM   #1 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
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?
H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 11th, 2007, 2:15 AM   #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 : /
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 11th, 2007, 9:12 AM   #3 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
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.
H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 11th, 2007, 7:12 PM   #4 (permalink)
Surpass Fan
Comfy Contributor
 
davotoula's Avatar
 
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
davotoula is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 12th, 2007, 1:26 PM   #5 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
Joined in Jul 2004
Lives in N,BC,CA
8,033 posts
Gave thanks: 48
Thanked 129 times
Do you know what event it traps? Like typing in a new address, tab closure, etc...?
H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 12th, 2007, 1:52 PM   #6 (permalink)
Surpass Fan
Comfy Contributor
 
davotoula's Avatar
 
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.
davotoula is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 12th, 2007, 2:49 PM   #7 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
Joined in Jul 2004
Lives in N,BC,CA
8,033 posts
Gave thanks: 48
Thanked 129 times
Interesting. Thanks
H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 13th, 2007, 12:02 PM   #8 (permalink)
L'Awesome Advocate
Super #1
 
Ancyru's Avatar
 
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.
Ancyru is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On