Location jquery href?

Possible duplicate:
How to create a redirect page in jQuery / JavaScript?

I remember there is a redirect function in jQuery.

It was like:

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

but what was that? I could not remember and can not find on Google.

+75
javascript jquery
Aug 16 2018-11-18T00:
source share
6 answers

No need for jQuery.

 window.location.href = 'http://example.com'; 
+83
Aug 16 2018-11-11T00:
source share

Using:

 window.location.replace(...) 

See this SO question for more information:

How to redirect to another webpage in javascript / jQuery?

Or perhaps you remember this:

 var url = "http://stackoverflow.com"; $(location).attr('href',url); 
+25
Aug 16 2018-11-11T00:
source share

easier:)

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

or

 location.replace('http://address.com'); // <-- no history saved. 
+24
Aug 16 2018-11-11T00:
source share

I think you are looking

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

this is not jquery, this is pure js.

+13
Aug 16 2018-11-11T00:
source share

Ideally, you want to use window.location.replace(...)

See this answer here for a full explanation: How to redirect to another webpage in JavaScript / jQuery?

+6
Aug 16 2018-11-11T00:
source share

You can use only Javascript:

 window.location = 'http://address.com'; 
+5
Aug 16 2018-11-11T00:
source share



All Articles