Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating location.href on Netscape 6/7 does not add to history stack 1

Status
Not open for further replies.

Thalhuber

Programmer
Jan 2, 2003
8
US
This one is driving me crazy!

I open a Popup window, and from that Popup window I update the opener URL like this:

opener.location.href = newurl

On all browsers I've tried (IE 4+, NN 4+), this updates the URL of the opener like it's supposed to.

However ... on Netscape 6.x or 7.x, changing the opener's location.href like this DOES NOT add an entry to the History stack. In other words, it acts like this instead:

opener.location.replace(newurl)

The result is you cannot use the Back button (or the history.back() fuction) to get back to the original page.

Any ideas on what's causing this, or how I can work around it?

 
This is a response to my own question. Hopefully this may help someone else avoid the frustration I went through to isolate this.

There definitely is a difference (Netscape bug) between IE (any level) and Netscape 6 or higher.

I have an environment with lots of Popup windows that communicate with each other. The Popup windows frequently update the contents (update the location.href property) of their Opener windows.

From a Popup window, if you modify the "location.href" property of the Opener window (opener.location.href = "newpage.htm") with javascript BEFORE the onLoad event of the Popup window occurs, it will effectively perform an opener.location.replace("newpage.htm") operation with Netscape 6/7. That is, the current history entry in the Opener window is replaced, instead of adding a new entry.

In the Popup window, this is an example of what fails with Netscape:

<html>
<head>
<script language=&quot;javascript&quot;>
opener.location.href=&quot;newpage.htm&quot;
self.close()
</script>
</head>
<body>
</body>
</html>


The above works fine in Netscape 4, and all levels of IE I've tried. I discovered by trial and error that if you wait to execute the same javascript code in the Popup window until AFTER its onLoad event, then the Opener window is updated properly (a new page is added to History instead of replacing the current entry). The following works with Netscape 6/7:

<html>
<head>
</head>
<body onLoad=&quot;opener.location.href='newpage.htm';self.close()&quot;>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top