JavaScript Oddity in FireFox

I have a web page that opens another popup page, and now I needed to also have it automatically redirect back to a previous page after it opened the popup.  I thought this would be very easy to do, and it was in IE, but it turned out to not be so easy in FireFox.

This is what I thought would work -- it does in IE, and each of the individual lines works on their own in FireFox, but together in FireFox you don't get a popup:
    window.open('NewPage.aspx');
    document.location = 'PreviousPage.aspx'; // window.location doesn't help, neither does location.href

The following is what turns out to work in both IE and FireFox -- I hope this trivial piece of JavaScript helps someone out there since it took me a few minutes:
    window.open('NewPage.aspx');
    location.replace('PreviousPage.aspx');


Published Wednesday, February 23, 2005 3:36 PM by PaulWilson

Comments

# Re: JavaScript Oddity in FireFox

Oh wow! I use location.href all over the place in my apps! Thanks for the tip.

Wednesday, February 23, 2005 4:14 PM by Jeffrey Palermo

# re: JavaScript Oddity in FireFox

kind of a strange scenario, isn't it?

Wednesday, February 23, 2005 10:17 PM by Ron Green

# re: JavaScript Oddity in FireFox

I tried what you wrote, and it's working just fine (Both on IE and Mozila)..

Why don't you change your proffesion instead of saying Mozila is not working well ????

Hate Microsoft...
Hate people who say Mozila is lower then IE...


Tuesday, March 01, 2005 5:23 AM by Gal

# re: JavaScript Oddity in FireFox

Hmmmm, I never said it was "lower" or not working -- I said there was an oddity. I use and recommend FireFox -- but I'm not a MS hater -- nor a MS drone.

Tuesday, March 01, 2005 6:35 AM by Paul Wilson

# re: JavaScript Oddity in FireFox

But Mozilla IS lower than IE....

Monday, March 14, 2005 11:16 AM by Tim

# re: JavaScript Oddity in FireFox

'Tim', I pity you.

Saturday, March 19, 2005 1:27 AM by netdrdroid9

# re: JavaScript Oddity in FireFox

I'm experiencing the problem in FireFox 1.5 and Netscape 8.1 however the solution has no effect. These browsers seem to ignore changes to window.location.href! IE works fine with: window.location = "newPage.html" window.location.href = "newPage.html" location.replace("newPage.html") FireFox and Netscape appear broken! That's the forth problem I've had with them today. Only one problem today with IE.

Thursday, August 10, 2006 3:19 AM by Joel Fowler

# re: JavaScript Oddity in FireFox

I just found the same problem in FF 1.5. My application uses 'location=...' in bunch of different ways via Event Handlers, functions, etc. I only had a problem with one specific instance within function called by a popup window and my fix was to make the URL an absolute. Ex: location = location.protocol + "//" + location.hostname + "/myfolder/myfile.html" I know this won't solve every problems but at least it might solve some problem. Hate Smucks... Hate people who would rather insult then help.

Tuesday, August 29, 2006 6:16 PM by Jake

# re: JavaScript Oddity in FireFox

The above did not work for me in Firefox But this did: window.open('new.php'); parent.window.self.close() Techback, LLC www.techback.net

Tuesday, September 26, 2006 1:31 PM by Techback, LLC

# re: JavaScript Oddity in FireFox

This didn't seem to work. I dug further and found this: http://www.codingforums.com/showthread.php?t=56428

Tuesday, October 31, 2006 6:29 PM by Shaun

# re: JavaScript Oddity in FireFox

Worked for me, now it works both in IE and FireFox, thanks a lot!

Friday, December 01, 2006 2:46 AM by Draiden

# re: JavaScript Oddity in FireFox

Good explanation from http://www.codingforums.com/showthread.php?t=56428

add return false; in FF otherwise a submit is performed (which does not happens in IE)

Friday, December 08, 2006 9:25 AM by Pierre Delnatte

# re: JavaScript Oddity in FireFox

Thanks!  It fixed the exact same problem we were having.

Monday, December 18, 2006 12:43 PM by Clint

# List of JavaScript functions don't work in mozila

List of JavaScript functions don't work in mozila 2 But work in Ie 6

Tuesday, February 06, 2007 5:59 AM by Mukesh doot

# document location firefox problem

Pingback from  document location firefox problem

Saturday, April 05, 2008 10:01 AM by document location firefox problem

Leave a Comment

(required) 
(required) 
(optional)
(required)