How to get the browser to navigate to URL in JavaScript

This question already has an answer here:

  • How do I redirect to another webpage? 67 answers

  • This works in all browsers:

    window.location.href = '...';
    

    If you wanted to change the page without it reflecting in the browser back history, you can do:

    window.location.replace('...');
    

    Try these:

  • window.location.href = 'http://www.google.com';
  • window.location.assign("http://www.w3schools.com");
  • window.location = 'http://www.google.com';
  • For more see this link: other ways to reload the page with JavaScript


    It seems that this is the correct way window.location.assign("http://www.mozilla.org");

  • https://developer.mozilla.org/en-US/docs/Web/API/Window/location
  • https://www.w3schools.com/js/js_window_location.asp
  • https://jstricks.com/javascript-redirect-page-redirection/
  • 链接地址: http://www.djcxy.com/p/1120.html

    上一篇: 在PHP中获取完整的URL

    下一篇: 如何让浏览器在JavaScript中导航到URL