0

I can navigate web pages with window.open("http://www.example.com", "_self"); and it will work with all browsers.

But when I use the following code:

function f1()
{
    window.navigate("http://www.example.com");
}

It only works in Internet Explorer. It won't work in Firefox or other browsers. Why? And how can I fix that?

Here is my HTML code:

<input id="Button1" type="button" value="Try" onclick="f1()" />
JJJ
  • 32,902
  • 20
  • 89
  • 102
Ali Vojdanian
  • 2,067
  • 2
  • 31
  • 47

2 Answers2

2

window.navigate is a non-standard Internet Explorer feature. Other browsers simply don't provide the function.

You could shim it with:

if (! window.navigate) {
    window.navigate = function (arg) {
        location.assign(arg);
    }
} 

… but your code would be better if you just rewrote it to use standard methods (i.e. the location object) in the first place.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Is window.open() standard method? – Ali Vojdanian Mar 01 '15 at 12:18
  • @aliboy38 MDN is a great reference for JavaScript, and most pages include browser support and links to the relevant spec. window.open doesn't have the best info, but it still tells you which browsers support each of its features: https://developer.mozilla.org/en-US/docs/Web/API/Window/open – Dave Mar 01 '15 at 12:38
-2

This could easily be the answer on your problem.. You're missing href.

window.location.href = 'URL';

Answer: Should I use window.navigate or document.location in JavaScript?

EDIT:

Well, was copied from wrong place.

Possible duplicate of:

button javascript works on IE but not firefox window.navigate()

Answer:

If you check the documentation for that method, you will see the quite common:

There is no public standard that applies to this method.

Community
  • 1
  • 1
Jesper
  • 3,816
  • 2
  • 16
  • 24
  • You are talking about another method. My question was about another method on how can I fix that and why is that happening? – Ali Vojdanian Mar 01 '15 at 12:13