How to go to a URL using jQuery?

This question already has an answer here:

  • How do I redirect to another webpage? 67 answers
  • How to get the browser to navigate to URL in JavaScript [duplicate] 3 answers
  • How do we update URL or query strings using javascript/jQuery without reloading the page? 10 answers

  • //As an HTTP redirect (back button will not work )
    window.location.replace("http://www.google.com");
    
    //like if you click on a link (it will be saved in the session history, 
    //so the back button will work as expected)
    window.location.href = "http://www.google.com";
    

    为什么不使用?

    location.href='http://www.example.com';
    

    <!DOCTYPE html>
    <html>
    
    <head>
      <script>
        function goToURL() {
          location.href = 'http://google.it';
    
        }
      </script>
    </head>
    
    <body>
      <a href="javascript:void(0)" onclick="goToURL(); return false;">Go To URL</a>
    </body>
    
    </html>

    window.location is just what you need. Other thing you can do is to create anchor element and simulate click on it

    $("<a href='your url'></a>").click(); 
    
    链接地址: http://www.djcxy.com/p/1936.html

    上一篇: jQuery位置href

    下一篇: 如何去使用jQuery的URL?