history.go('url') issue

后端 未结 3 1709
野性不改
野性不改 2020-12-19 17:58

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

相关标签:
3条回答
  • 2020-12-19 18:27

    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 ;-)

    0 讨论(0)
  • 2020-12-19 18:36

    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.

    0 讨论(0)
  • 2020-12-19 18:53

    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 讨论(0)
提交回复
热议问题