4

Can you please tell me why window.location.href is not working on firefox?

Code:

<script>

     function goToURL() {
           window.location.href('url');
     }

</script>

What can I use instead of window.location.href as an alternative?

Stuart
  • 711
  • 1
  • 11
  • 35
Vishal Beri
  • 47
  • 1
  • 1
  • 3
  • Use it in what way, exactly? Please expand on your question - read http://stackoverflow.com/questions/ask-advice for more information. – Andy E Nov 19 '10 at 14:57
  • What are you trying to do? This may help you: http://stackoverflow.com/questions/275092/windows-location-href-not-working-on-firefox3 – demux Nov 19 '10 at 14:58
  • This is really not an answerable question in its current form, as it doesn't really make sense. You should state what you're trying to *achieve*, possibly giving your current code, and ask for advice of how to improve it. – Andrzej Doyle Nov 19 '10 at 15:06

4 Answers4

5

This should work in both IE and FireFox:

window.location.assign(url);
Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
  • `replace()` will replace the current page in the history, whereas assigning to `href` doesn't. `assign()` is a more appropriate alternative. – Andy E Nov 19 '10 at 15:00
  • @Andy E - You're right. Updated. – Justin Niessner Nov 19 '10 at 15:02
  • Thank you! After many headaches, testing location.href (which works in IE and not FF), etc. this finally works in both as of today. – Adam Mar 03 '17 at 21:39
2

You use it for example like this:

window.location.href = 'http://www.guffa.com';

I have verified that this code works in Firefox 3.6.12.

If that doesn't work for you, you have to be more specific in your question about what the exact problem is.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

use it with an assignment

window.location = "http://...";

anyway you should be more specific in your question

0

Here is answere for You:

windows.location.href not working on Firefox3

Community
  • 1
  • 1
Beiru
  • 312
  • 5
  • 13
  • That's not a good answer though. It might make it work in Firefox for some reason, but it stops working in some other browsers. Setting `window.location.href` works in Firefox, so there is something else that is the problem. – Guffa Nov 19 '10 at 15:12
  • You are right, thanks for pointing this out. – Beiru Nov 19 '10 at 15:24