最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - history.go('url') issue - Stack Overflow

programmeradmin0浏览0评论

I've seen that history.go() method can have two types of parameter:

see:

 .asp 

But url does not working at all.

I use JavaScript console of browser to test this method but got no success.

I know that there are security issues, that you can't read history entries. You can just go back and forward.

So why this string parameter listed in all js references?

I've seen that history.go() method can have two types of parameter:

see:

 http://www.w3schools.com/jsref/met_his_go.asp 

But url does not working at all.

I use JavaScript console of browser to test this method but got no success.

I know that there are security issues, that you can't read history entries. You can just go back and forward.

So why this string parameter listed in all js references?

Share Improve this question edited Nov 26, 2015 at 14:13 pnuts 59.5k11 gold badges91 silver badges141 bronze badges asked Jun 8, 2011 at 10:20 VikasVikas 24.3k37 gold badges118 silver badges159 bronze badges 5
  • Which browser and version are you trying this with? – paulmorriss Commented Jun 8, 2011 at 10:27
  • Tried in Chrome latest and Mozilla firefox 4.1 or latest (whatever).. – Vikas Commented Jun 8, 2011 at 10:32
  • 1 w3schools is not "all js references". It's one, particularly bad reference. – Lightness Races in Orbit Commented Jun 8, 2011 at 10:33
  • FWIW, I've found help.dottoro.com to be a better reference. It's far from perfect but they do mention browser differences like this and offer a quick overview of browser support. help.dottoro.com/ljhvjqec.php is their page for history.go(). – Andy E Commented Jun 8, 2011 at 10:36
  • 1 I raised this question because I see another bad reference (here), so now learned that MDC is the best! – Vikas Commented Jun 8, 2011 at 10:37
Add a comment  | 

3 Answers 3

Reset to default 12

Supplying a URL as a parameter is a non-standard feature and will not work in all browsers. Most browsers accept only a relative number, e.g. 1 or -1.

From the MDC documentation (emphasis mine):

[history.go(integerDelta)] Loads a page from the session history, identified by its relative location to the current page, for example -1 for the previous page or 1 for the next page. When integerDelta is out of bounds (e.g. -1 when there are no previously visited pages in the session history), the method doesn't do anything and doesn't raise an exception. Calling go() without parameters or with a non-integer argument has no effect (unlike Internet Explorer, which supports string URLs as the argument).

This is what happens when you use W3Schools as a learning resource ;-)

MDC at least has this note:

Note: Internet Explorer supports passing string URLs as a parameter to go(); this is non-standard and not supported by Gecko.

No idea why it is listed in many references, though.

If you want to use it with an URL just use:

window.location.href="http://www.whereyouwannago.nl/";

The URL is problably still there for backwards compatibility

发布评论

评论列表(0)

  1. 暂无评论