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.replace("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
LVL 3
dapperryAsked:
Who is Participating?
 
a.marshConnect With a Mentor Commented:
I have tried and tested the code and it works in Netscape (aswell as IE).

Just to clarify....

Change:

self.opener.location.replace("logout.cfm");

to:

self.opener.setTimeout("window.location.replace('logout.cfm');", 10);


Wrapping this question up.

:o)

Ant
0
 
a.marshCommented:
Should work...could it be because of:

<script language="javscript">

which should be:

<script language="javascript">


????

Ant
0
 
a.marshCommented:
Or could it be because the reference to the opener gets lost........

:o\

Ant
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
dapperryAuthor Commented:
Fixed the <script language="javascript"> and it still doesn't work. What else could be wrong?

:) dapperry
0
 
a.marshCommented:
What version of Netscape are you using?

Try using this to try and narrow down where the issue is:

onunload="alert('test!');"


Ant
0
 
dapperryAuthor Commented:
I'm using Communicator 4.7

I tried that, but no alert seems to come up.

:) dapperry
0
 
dapperryAuthor Commented:
Do you think its something in the way I set up the frameset itself?
0
 
a.marshCommented:
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
0
 
dapperryAuthor Commented:
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.location.replace('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
0
 
a.marshCommented:
What about putting the onunload in the frame instead of the frameset?

Ant
0
 
a.marshCommented:
My last comment is unlikely to help to be quite honest - but worth a try!

Ant
0
 
dapperryAuthor Commented:
Just tried putting it in the frame, but it still didn't fire the event.

:) dapperry
0
 
a.marshCommented:
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
0
 
a.marshCommented:
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>
0
 
dapperryAuthor Commented:
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.replace("logout.cfm");

:) dapperry
0
 
a.marshCommented:
What about just trying:

self.opener.location = 'logout.cfm'


Ant
0
 
dapperryAuthor Commented:
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
0
 
dapperryAuthor Commented:
Maybe upping the pts some more will get some more chefs into the kitchen (No offense Ant, but I need an answer)

:) dapperry
0
 
rpoloczCommented:
so setting window.opener.location.href='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?
0
 
a.marshCommented:
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.cfm");
    }
</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
0
 
a.marshCommented:
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.replace("logout.cfm");

to:

self.opener.setTimeout("window.location.replace('logout.cfm');", 10);


And it works in Netscape!!

:o)

Ant
0
 
Michel PlungjanIT ExpertCommented:
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('logout.cfm','mainwin','replace')">

Michel

0
 
Michel PlungjanIT ExpertCommented:
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
0
 
a.marshCommented:
Yes, really! :oP

Ant
0
 
Michel PlungjanIT ExpertCommented:
Also when the window is closed??? It never used to work

Michel
0
 
a.marshCommented:
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
0
 
Michel PlungjanIT ExpertCommented:
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
0
 
a.marshCommented:
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("window.location.replace('logout.cfm');", 10);


:o)

Ant
0
 
Michel PlungjanIT ExpertCommented:
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
0
 
a.marshCommented:
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
0
 
Michel PlungjanIT ExpertCommented:
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
0
 
a.marshCommented:
I've tried it with Netscape 4.7 on Windows ME - everything worked fine....

Ant
0
 
Michel PlungjanIT ExpertCommented:
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
0
 
dapperryAuthor Commented:
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
0
 
a.marshCommented:
Glad to have helped.

Thanks for the A!

:o)

Ant
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.