How to go to a URL using jQuery? [duplicate]

How to go to a URL using jQuery? [duplicate]

This question already has an answer here:

How do I redirect to another webpage?

58 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

How to go to a URL using jQuery or JavaScript.

function goToURL(url){
// some code to go to url


I don’t want to use window.location as I want to invoke this link from a popup.
New link should also open in a popup. I also don’t want to use Ajax. Just simulate href in JavaScript.


Solution 1:

//As an HTTP redirect (back button will not work )

//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 = "";

Solution 2:

why not using?

<!DOCTYPE html>

    function goToURL() {
      location.href = '';


  <a href="javascript:void(0)" onclick="goToURL(); return false;">Go To URL</a>

Related:  Read id3 v2.4 tags with native Chrome Javascript/FileReader/DataView

Solution 3:

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

Solution 4:

Actually, you have to use the anchor # to play with this. If you reverse engineer the Gmail url system, you’ll find

Everything after # is the part your want to load in your page, then you just have to chose where to load it.

By the way, using document.location by adding a #something won’t refresh your page.