dapperry
asked on
Problem w/ onunload event
I open app window. I have it open up a 1 frame frameset, so that I can go to a logout page when the window is closed by the user. Heres the code for the frame. It works in IE, but in Netscape the onunload event never seems to fire:
<script language="javscript">
function LogOut() {
self.opener.location.repla ce("logout .cfm");
}
</script>
<frameset title="Rapid MMS" onunload="LogOut()" rows="100%,*">
<frame src="welcome.cfm" name="main" frameborder="0" scrolling="Auto" framespacing="0" title="Rapid MMS" border="0">
</frameset>
Any help would be much appreciated. I'm sure I am doing something stupid.
:) dapperry
<script language="javscript">
function LogOut() {
self.opener.location.repla
}
</script>
<frameset title="Rapid MMS" onunload="LogOut()" rows="100%,*">
<frame src="welcome.cfm" name="main" frameborder="0" scrolling="Auto" framespacing="0" title="Rapid MMS" border="0">
</frameset>
Any help would be much appreciated. I'm sure I am doing something stupid.
:) dapperry
Or could it be because the reference to the opener gets lost........
:o\
Ant
:o\
Ant
ASKER
Fixed the <script language="javascript"> and it still doesn't work. What else could be wrong?
:) dapperry
:) dapperry
What version of Netscape are you using?
Try using this to try and narrow down where the issue is:
onunload="alert('test!');"
Ant
Try using this to try and narrow down where the issue is:
onunload="alert('test!');"
Ant
ASKER
I'm using Communicator 4.7
I tried that, but no alert seems to come up.
:) dapperry
I tried that, but no alert seems to come up.
:) dapperry
ASKER
Do you think its something in the way I set up the frameset itself?
No - but it wouldn't surprise me if the problem is the fact that you are using 4.7 - that was a buggy version of Netscape - could you try using a different version (older or newer)?
Ant
Ant
ASKER
I upgraded to 4.77 and still got the same problem. Now I have Netscape 6, but it sucks becuase its slower than molasses, but the alert does come up. Anyhow, I can't very well create an app that won't work a great many browsers. Funny thing though if I have onunload="self.opener.loca tion.repla ce('logout .cfm')" it still doesn't work. However, in this instance if I look at the Javascript console I get the following error message:
JavaScript Error: illegal URL method 'logout.cfm'
Does this tell anybody anything?
:) dapperry
PS - I'm upping the pts so I can get this resolved quickly
JavaScript Error: illegal URL method 'logout.cfm'
Does this tell anybody anything?
:) dapperry
PS - I'm upping the pts so I can get this resolved quickly
What about putting the onunload in the frame instead of the frameset?
Ant
Ant
My last comment is unlikely to help to be quite honest - but worth a try!
Ant
Ant
ASKER
Just tried putting it in the frame, but it still didn't fire the event.
:) dapperry
:) dapperry
The javascript error you are talking about - does it appear in Netscape 4 or 6?
If 4, then do you get an error when you try the alert()?
Ant
If 4, then do you get an error when you try the alert()?
Ant
You mentioned earlier about the fact you only have one frame, perhaps try:
<frameset title="Rapid MMS" onunload="LogOut()" rows="100%,*">
<frame src="welcome.cfm" name="main" frameborder="0" scrolling="Auto" framespacing="0" title="Rapid MMS" border="0">
<frame src="">
</frameset>
<frameset title="Rapid MMS" onunload="LogOut()" rows="100%,*">
<frame src="welcome.cfm" name="main" frameborder="0" scrolling="Auto" framespacing="0" title="Rapid MMS" border="0">
<frame src="">
</frameset>
ASKER
That didn't work, but this does:
<script language="javascript">
function LogOff() {
self.opener.alert("hi");
}
</script>
<frameset title="Rapid MMS" onunload="LogOut()" rows="100%,*">
<frame src="welcome.cfm" name="main" frameborder="0" scrolling="Auto" framespacing="0" title="Rapid
MMS" border="0">
</frameset>
So is there something wrong with:
self.opener.location.repla ce("logout .cfm");
:) dapperry
<script language="javascript">
function LogOff() {
self.opener.alert("hi");
}
</script>
<frameset title="Rapid MMS" onunload="LogOut()" rows="100%,*">
<frame src="welcome.cfm" name="main" frameborder="0" scrolling="Auto" framespacing="0" title="Rapid
MMS" border="0">
</frameset>
So is there something wrong with:
self.opener.location.repla
:) dapperry
What about just trying:
self.opener.location = 'logout.cfm'
Ant
self.opener.location = 'logout.cfm'
Ant
ASKER
Just tried that, and it didn't work either. Still got the:
illegal URL method 'logout.cfm'.
This the case in any Netscape 4.7x. I get no errors in NS 6
Weird, but alert(self.opener.location .href); actually gives the correct URL for the parent window that opened the App window, but then when you try to set the same property it gives you the error I just mentioned above. Maybe its losing the opener reference. Is there anyway to get some sort of index for the opener window, and then try to reference the opener window that way?
:) dapperry
illegal URL method 'logout.cfm'.
This the case in any Netscape 4.7x. I get no errors in NS 6
Weird, but alert(self.opener.location
:) dapperry
ASKER
Maybe upping the pts some more will get some more chefs into the kitchen (No offense Ant, but I need an answer)
:) dapperry
:) dapperry
so setting window.opener.location.hre f='logout. cfm'; also gives the error? If so, try lowering the browser security permissions. And logout.cfm is the correct local path, not /logout.cfm? And logout.cfm complies correctly? Did it work in NS 6?
Okay - I've been playing around with this a little bit and have come across something strange....
Instead of doing the redirect in the child window, I thought we could do it in the parent window. Try the following code and see the odd effect you get in Netscape 9again it works perfectly in IE.
test.html
-------------------------- ---------- ---------- --
<html>
<head>
<script language="javascript">
<!--
var newwin = window.open("test2.html", "", "width=200,height=200");
function test(val){
alert(val);
window.location = val;
}
//-->
</script>
</head>
<body>
</body>
</html>
test2.html
-------------------------- ---------- ---------- --
<html>
<head>
<script language="javascript">
function LogOut() {
self.opener.test("logout.c fm");
}
</script>
</head>
<frameset title="Rapid MMS" onunload="LogOut()" rows="100%,*">
<frame src="welcome.cfm" name="main" frameborder="0" scrolling="Auto" framespacing="0" title="Rapid MMS" border="0">
</frameset>
</html>
Now if anything it proves that in Netscape you can still reference the window.opener okay - there is just some real problem with redirecting.
If you call the test() function from within the parent window, for example, add this code to the parent window:
<a href="javascript: test('logout.cfm');">click me</a>
the function works fine!!
:oP
Ant
Instead of doing the redirect in the child window, I thought we could do it in the parent window. Try the following code and see the odd effect you get in Netscape 9again it works perfectly in IE.
test.html
--------------------------
<html>
<head>
<script language="javascript">
<!--
var newwin = window.open("test2.html", "", "width=200,height=200");
function test(val){
alert(val);
window.location = val;
}
//-->
</script>
</head>
<body>
</body>
</html>
test2.html
--------------------------
<html>
<head>
<script language="javascript">
function LogOut() {
self.opener.test("logout.c
}
</script>
</head>
<frameset title="Rapid MMS" onunload="LogOut()" rows="100%,*">
<frame src="welcome.cfm" name="main" frameborder="0" scrolling="Auto" framespacing="0" title="Rapid MMS" border="0">
</frameset>
</html>
Now if anything it proves that in Netscape you can still reference the window.opener okay - there is just some real problem with redirecting.
If you call the test() function from within the parent window, for example, add this code to the parent window:
<a href="javascript: test('logout.cfm');">click
the function works fine!!
:oP
Ant
Got it!!!!!!!!
For some reason (I've seen this issue before) Netscape needs to have a slight delay.
All you need to do is change one line of your original code.
Change:
self.opener.location.repla ce("logout .cfm");
to:
self.opener.setTimeout("wi ndow.locat ion.replac e('logout. cfm');", 10);
And it works in Netscape!!
:o)
Ant
For some reason (I've seen this issue before) Netscape needs to have a slight delay.
All you need to do is change one line of your original code.
Change:
self.opener.location.repla
to:
self.opener.setTimeout("wi
And it works in Netscape!!
:o)
Ant
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Really???
I would have thought that the unload cleared too much...
Does it work if the user click the [x] too????
I would have thought this woudl be safer:
in opener:
<script>
window.name="mainwin"
</script>
in popup
<frameset onUnload="window.open('log out.cfm',' mainwin',' replace')" >
Michel
I would have thought that the unload cleared too much...
Does it work if the user click the [x] too????
I would have thought this woudl be safer:
in opener:
<script>
window.name="mainwin"
</script>
in popup
<frameset onUnload="window.open('log
Michel
even
<frameset onUnload="window.open('http://www.server.com/logout.cfm','mainwin','replace')">
to be on the safe side in case Netscape forgets where he is
Michel
<frameset onUnload="window.open('http://www.server.com/logout.cfm','mainwin','replace')">
to be on the safe side in case Netscape forgets where he is
Michel
Yes, really! :oP
Ant
Ant
Also when the window is closed??? It never used to work
Michel
Michel
We don't need to open a new window though Michel - we are simply changing the location of the parent window.
The onUnload event was firing in Netscape - we were just getting an error when trying to change the location of the parent window - and the way that I solved it was to set a timeout on the parent window to do the redirection.
I tried it on Netscape 4.7 on Windows and it worked.
:o)
Ant
The onUnload event was firing in Netscape - we were just getting an error when trying to change the location of the parent window - and the way that I solved it was to set a timeout on the parent window to do the redirection.
I tried it on Netscape 4.7 on Windows and it worked.
:o)
Ant
That is not what I mean - IF the user closes the window I think you STILL want to logout, no?
And I wonder if it still finally in Netscape to have an onload that is triggered by a closing window call a script that uses window attributes like a document.form or an opener
Michel
And I wonder if it still finally in Netscape to have an onload that is triggered by a closing window call a script that uses window attributes like a document.form or an opener
Michel
The situation as I see it is that the user logs in and (on successful login) a popup window is created (which contains a frameset so as to "hide" the URLs of the pages visited).
Upon the user closing that popup window, the system forces a logout by redirecting the parent window (that opened the child window) to the logout.cfm page.
The issue was that Netscape didn't seem to want to redirect the parent window - hence I discovered the way to get it to do that:
self.opener.setTimeout("wi ndow.locat ion.replac e('logout. cfm');", 10);
:o)
Ant
Upon the user closing that popup window, the system forces a logout by redirecting the parent window (that opened the child window) to the logout.cfm page.
The issue was that Netscape didn't seem to want to redirect the parent window - hence I discovered the way to get it to do that:
self.opener.setTimeout("wi
:o)
Ant
yeees, and my question was, does your timeout actually work when the user CLOSE the window and not just navigate away in that window - if so a very old netscape problem has been solved - e.g netscape forgets everything including scripts and openers when the x in the corner is used to close a window
Michel
Michel
And as I've already said - yes it does work when you close the window - at least in version 4.7 on Windows which I have tested.
:o)
Ant
:o)
Ant
Did you try to look at the javascript console?
I get "JavaScript Error: out of memory "
but it does work in ns 4.7 on NT
Michel
I get "JavaScript Error: out of memory "
but it does work in ns 4.7 on NT
Michel
I've tried it with Netscape 4.7 on Windows ME - everything worked fine....
Ant
Ant
The out of memory error does however support my notion that NS is very unhappy doing anything onUnload
Using the opener to do it's own location change is clever though
Michel
Using the opener to do it's own location change is clever though
Michel
ASKER
Yes, that works completely. Cool!! Yes, the pop up window is fired after the person logs in. I actually make the window without menus, and also use a right mouse disable js function (that I believe Michel gave me a while back), so that the user has to use my navigation buttons, and the 'Back' button, etc. doesn't come into play. When I close the pop-up window (and destroy the 1 frame frameset) the logout page is loaded in the parent window, so I can do some logging, etc. Thanks again!
:) dapperry
:) dapperry
Glad to have helped.
Thanks for the A!
:o)
Ant
Thanks for the A!
:o)
Ant
<script language="javscript">
which should be:
<script language="javascript">
????
Ant