[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 784
  • Last Modified:

JavaScript - window.location.href problem

Hi,

I have a html file called child.htm which is fairly basic. It checks once every second if its parent is still open. If it is closed then it is supposed to call an ASP page called Logout_cl.asp which will log the user out of business objects. child.htm and Logout_cl.asp are in the same directory. Here's the code:

<html>
<head>
<title>Logout</title>
<script language="JavaScript">

function checkParent() {  
   oInterval = window.setInterval("checkParentAlive()", 1000);
}

function checkParentAlive() {
   if(opener.closed) {
       window.location.href = "Logout_cl.asp";
       window.close();
   }
}
</script>
</head>
<body onLoad="checkParent();">
</body>
</html>

Logout_cl.asp is never reached (there's an alert in there which never pops up). I'm not sure what I'm doing wrong - probably something fairly small and ridiculous! Hopefully someone can point it out to me. If you need any more detail, let me know.
Thanks,
Jenny
0
jenpenod
Asked:
jenpenod
  • 2
  • 2
  • 2
1 Solution
 
pietertje1983Commented:
It seems to me you change first the location to the ASP page and directly after you close the window.
window.location.href = "Logout_cl.asp"; //<-- here you change it
window.close(); //<-- and directly after close the same window
0
 
Sowmya_KCommented:
The window.opener.closed works in IE 6 but not in Mozilla or Opera due to a known bug. Refer this link to see the details of the known bug:  https://bugzilla.mozilla.org/show_bug.cgi?id=165418

The solution for this problem is the following JavaScript snippet:
if(!window.opener || window.opener.closed)
For Mozilla/Netscape/Opera, the first part of the if statement will trigger (until they fix their bugs). For IE 6 the first part will not trigger but the second one will.

Also, in IE 5 window.opener.closed DOES NOT work correctly due to another known bug.  However the above code does not solve the problem in IE 5.Refer http://support.microsoft.com/default.aspx?scid=kb;en-us;241109 for the workaround microsoft provides


0
 
jenpenodAuthor Commented:
pietertje1983:
I do close the window after re-directing but do you not think it would run the code on Logout_cl.asp first? ie. Log the user out of business objects and display the alert message that I've put in. This is currently not happening.

Sowmya_K:
Thanks for the details of those bugs but am I actually using IE6 so it's ok - I am definitely able to get in to that if statement. I put in an alert just before the window.location.href line and it printed out ok.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Sowmya_KCommented:
did u try window.location.replace ?
0
 
pietertje1983Commented:
I think you can better close the window with javascript in the file "Logout_cl.asp" after logging out, so you know for sure it will be called.
0
 
jenpenodAuthor Commented:
pietertje1983:
Thanks for your help. I removed the window.close() and it's re-directing fine now.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now