JavaScript - window.location.href problem

Posted on 2006-05-05
Last Modified: 2008-02-01

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:

<script language="JavaScript">

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

function checkParentAlive() {
   if(opener.closed) {
       window.location.href = "Logout_cl.asp";
<body onLoad="checkParent();">

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.
Question by:jenpenod
    LVL 2

    Expert Comment

    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
    LVL 4

    Expert Comment

    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:

    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;en-us;241109 for the workaround microsoft provides


    Author Comment

    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.

    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.
    LVL 4

    Expert Comment

    did u try window.location.replace ?
    LVL 2

    Accepted Solution

    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.

    Author Comment

    Thanks for your help. I removed the window.close() and it's re-directing fine now.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
    The viewer will learn how to count occurrences of each item in an array.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now