PDA

View Full Version : onLoad function didn't work on Firefox



novarli
08-28-2006, 06:39 AM
I have external javascript scripts



function window_close(id){
window.open("logout2.php?id="+id,"Logout","width=470,heigth=340");
}


In file php named list.php in body tag



<body onUnload="window_close('<? echo $_GET["id"] ;?>')">


In IE when i close the window (click x ) the code work. But in mozilla firefox it didn't work.
Why?

One more question can javascript detect browser's back button click or not click?

mwinter
08-28-2006, 11:07 AM
I have external javascript scripts



function window_close(id){
window.open("logout2.php?id="+id,"Logout","width=470,heigth=340");
}


In file php named list.php in body tag



<body onUnload="window_close('<? echo $_GET["id"] ;?>')">


If the user is closing the browser or leaving your site, you should consider it too late to do anything. You want to have the user do something, make a point of telling them. In any case, you'll still need to handle a user that doesn't log out (or whatever).

You may be able to remind the user:



this.onbeforeunload = function() {
if (notReadyToLeave) {
return 'You haven't saved your work!';
}
};

but once they're going, it's too late to expect the browser to do anything.



In IE when i close the window (click x ) the code work. But in mozilla firefox it didn't work.
Why?

A pop-up blocker could prevent what you're attempting, so you're off to a bad start as it is, but I ask you: Why not? If the user has instructed the browser to close, why should it reopen a connection and make another request to the server? Why should it disobey the user and stay open?



One more question can javascript detect browser's back button click or not click?

The unload (and beforeunload) event fires for many reasons; you can't determine which applies.

Mike

novarli
08-29-2006, 01:44 AM
After i checked it in firefox was work, but in single window. Not in tab.

Is the event this.onbeforeunload can be applied in tab window?

mwinter
08-29-2006, 12:40 PM
After i checked it in firefox was work, but in single window. Not in tab.

Is the event this.onbeforeunload can be applied in tab window?

It works fine here, though support may be version-dependent. Also note that there are some browsers where it won't work at all; this is only an aid to users, nothing more.

To invoke the prompt, return a string (including an empty one). To bypass it, return undefined (either allow the function to drop out without encountering a return statement, or use "return;").

Mike