|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
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.
__________________
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++; } |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > Onunload behavior different in FF / IE ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|