jQuery location href

JavascriptJquery

Javascript Problem Overview


I remember there's a redirect function in jQuery.

It was like:

$(location).href('http://address.com')

But what was it exactly? I couldn't remember and can't find it using Google Search.

Javascript Solutions


Solution 1 - Javascript

There's no need for jQuery.

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

Solution 2 - Javascript

Use:

window.location.replace(...)

See this Stack Overflow question for more information:

https://stackoverflow.com/questions/503093/

Or perhaps it was this you remember:

var url = "http://stackoverflow.com";
location.href = url;

Solution 3 - Javascript

This is easier:

location.href = 'http://address.com';

Or

location.replace('http://address.com'); // <-- No history saved.

Solution 4 - Javascript

I think you are looking for:

window.location = 'http://someUrl.com';

It's not jQuery; it's pure JavaScript.

Solution 5 - Javascript

Ideally, you want to be using window.location.replace(...).

See this answer here for a full explanation: https://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery

Solution 6 - Javascript

You can use just JavaScript:

window.location = 'http://address.com';

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBenjaminView Question on Stackoverflow
Solution 1 - JavascriptDogbertView Answer on Stackoverflow
Solution 2 - JavascriptCurtisView Answer on Stackoverflow
Solution 3 - JavascriptJoseph MarikleView Answer on Stackoverflow
Solution 4 - JavascripttotallyNotLizardsView Answer on Stackoverflow
Solution 5 - JavascriptJamie DixonView Answer on Stackoverflow
Solution 6 - JavascriptRobertView Answer on Stackoverflow