Should I use window.navigate or [removed] in JavaScript?

前端 未结 11 1598
小鲜肉
小鲜肉 2020-11-27 12:12

What\'s the preferred method to use to change the location of the current web page using JavaScript? I\'ve seen both window.navigate and document.location used. Are there an

相关标签:
11条回答
  • 2020-11-27 12:48

    window.location will affect to your browser target. document.location will only affect to your browser and frame/iframe.

    0 讨论(0)
  • 2020-11-27 12:49

    I'd go with window.location = "http://...";. I've been coding cross-browser JavaScript for a few years, and I've never experienced problems using this approach.

    window.navigate and window.location.href seems a bit odd to me.

    0 讨论(0)
  • 2020-11-27 12:50

    support for document.location is also good though its a deprecated method. I've been using this method for a while with no problems. you can refer here for more details:

    https://developer.mozilla.org/en-US/docs/Web/API/document.location

    0 讨论(0)
  • 2020-11-27 12:52

    document.location is a (deprecated but still present) read-only string property, replaced by document.url.

    0 讨论(0)
  • 2020-11-27 12:57
    window.location.href = 'URL';
    

    is the standard implementation for changing the current window's location.

    0 讨论(0)
  • 2020-11-27 12:57

    window.navigate is NOT supported in some browsers, so that one should be avoided. Any of the other methods using the location property are the most reliable and consistent approach

    0 讨论(0)
提交回复
热议问题