JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 24th, 2006, 11:15 PM
venutip venutip is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 11 venutip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 2 sec
Reputation Power: 0
Onunload behavior different in FF / IE ?

Hi. I have a function that gets called on unload, like so:

Code:
<body onunload="clearLock();">


In my cross-browser testing, I have noticed that Firefox and IE seem to call the onunload function at different times. IE calls it immediately after the page is closed, whereas Firefox appears to call it after the next requested page has loaded.

Has anybody else noticed this? It is really screwing me up, because I'm using the onunload function to call a PHP script that "unlocks" a resource that was "locked" during the page load. In IE, everything is fine (imagine that); but because of the way Firefox seems to work, the clearLock script is always the last thing to run -- meaning that in Firefox, the resource can never be locked. (If anybody requests it I'll post the revelant PHP code later).

I have searched everywhere for an answer to this onunload question, but haven't had any luck. If anybody can help, I'd really appreciate it.

Thanks.

Reply With Quote
  #2  
Old September 25th, 2006, 05:48 AM
deanbayley's Avatar
deanbayley deanbayley is offline
Disturbed
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Somewhere In the Great Unknown
Posts: 494 deanbayley User rank is Corporal (100 - 500 Reputation Level)deanbayley User rank is Corporal (100 - 500 Reputation Level)deanbayley User rank is Corporal (100 - 500 Reputation Level)deanbayley User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 1 h 11 m 46 sec
Reputation Power: 8
Send a message via ICQ to deanbayley
Perhaps if you explain what you are locking we could help more but hows about using ajax to update a database (could even be a text file) every 5 secs to the current server time, then, a php script that runs on a cron job every 10 secs (or more) that checks all records older than 10 secs, that way the browser wouldn't have to tell you it'd closed, don't forget if the browser crashes (*ahem* IE *ahem*) then the onunload event wont fire anyway...

Sometimes we get stuck in one way of thinking..

Think of every element of your design as a directory, if you can't make something work go up a directory...

so rather than thinking "how can i get onunload to fire?" think "how can i avoid using onunload?"

HTH

D.
Comments on this post
Kravvitz agrees!
__________________
Put your hand on a hot stove for a minute, and it seems like an hour.
Sit with a pretty girl for an hour and it seems like a minute.
That's relativity.
- Albert Einstein

while($girl=='ugly')
{
$alcohol++;
}

Reply With Quote
  #3  
Old September 25th, 2006, 08:32 PM
venutip venutip is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 11 venutip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 2 sec
Reputation Power: 0
I'm not really locked in to onunload, but it does seem like a sensible way to handle it, and if it weren't for the browser issue ...

The details are, it's a simple CMS that my clients use to write articles (by entering text into a web form). To prevent more than one person from editing an article at the same time, I "lock" the article when somebody opens it by setting a flag in the database (post_owner='some user ID'). I figure that the only way I can keep the article from becoming forever locked (or at least, until the session times out) is by having that onunload function. The onunload function calls a PHP script that clears the lock (post_owner='0'). Maybe there is a better way to do it, but this seemed pretty simple (at the time, anyway).

I suppose I could try it your way too, with the cron job. You're right that the browser-based method doesn't protect against a browser crash or power outage or whatever. It seems a bit excessive to run a job every 10 seconds though, or even every minute. Kind of like going after a mouse with a shotgun, you know?

Reply With Quote
  #4  
Old September 26th, 2006, 03:52 AM
deanbayley's Avatar
deanbayley deanbayley is offline
Disturbed
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Somewhere In the Great Unknown
Posts: 494 deanbayley User rank is Corporal (100 - 500 Reputation Level)deanbayley User rank is Corporal (100 - 500 Reputation Level)deanbayley User rank is Corporal (100 - 500 Reputation Level)deanbayley User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 1 h 11 m 46 sec
Reputation Power: 8
Send a message via ICQ to deanbayley
Mouse? shotgun? no no no, everyone knows you use chainsaws to hunt mice lol...

they are very simple querys and should have little to no effect on server performance, just imagine that someone's browser does crash using the onunload method, you would manually have to unlock the post, that causes you hastle and the client

D.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Onunload behavior different in FF / IE ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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 not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT