5

Possible Duplicate:
button javasript works on IE but not firefox window.navigate()

I would like my page to navigate after selecting a select item.

I got the following error:

Uncaught TypeError: Object [object DOMWindow] has no method 'navigate'

    function go(to)
{
    window.navigate("feltoltott_kepek_elozmeny.php?show="+to);
}


onchange="javascript:go(this.value)"

Could somebody help me? Thanks.

I got more than one solution. Which one should I choose? Which is working in every browser?

Community
  • 1
  • 1
  • also see [Should I use window.navigate or document.location in JavaScript?](http://stackoverflow.com/questions/948227/should-i-use-window-navigate-or-document-location-in-javascript) – Felix Kling May 23 '11 at 08:46
  • also javascript: in an event handler is only necessary in IE when you have a VBScript as the first script block in the page. Nowhere else – mplungjan May 23 '11 at 08:48

3 Answers3

8

Please use

window.location.href = "feltoltott_kepek_elozmeny.php?show=" + to;
dexter
  • 13,365
  • 5
  • 39
  • 56
  • 3
    window.navigate() is the IE-specific way of assigning a value to the window.location.href property :) – dexter May 23 '11 at 08:43
1

try:

window.location.href = YOUR_URL;

;)

metaforce
  • 1,337
  • 5
  • 17
  • 26
1

You're looking for window.location.assign():

function go(to) {
    window.location.assign("feltoltott_kepek_elozmeny.php?show=" + to);
}

You can also assign a value directly to window.location or window.location.href:

window.location = "feltoltott_kepek_elozmeny.php?show=" + to;
window.location.href = "feltoltott_kepek_elozmeny.php?show=" + to;

See the Mozilla docs for window.location.

Andy E
  • 338,112
  • 86
  • 474
  • 445
  • 1
    Never seen .assign - and it seems to be the default method anyway: [Whenever a property of the location object is modified, a document will be loaded using the URL as if window.location.assign() had been called with the modified URL.](https://developer.mozilla.org/en/DOM/window.location#Methods) – mplungjan May 23 '11 at 08:45
  • @mplungjan: I can vaguely remember it, but I've always been using the `location.href` approach. Perhaps the method exists in case someone is feels more comfortable with using functions. – Lekensteyn May 23 '11 at 08:47
  • @Leken I really should load MDC and read every page. Seems every time I go there, I see something I did not know or that changed over the years. Still my (old-skool) coding works on all browsers still :) – mplungjan May 23 '11 at 08:51