开发者

jQuery location href [duplicate]

开发者 https://www.devze.com 2023-03-28 05:27 出处:网络
This question already has answers here: 开发者_如何转开发How do I redirect to another webpage?
This question already has answers here: 开发者_如何转开发 How do I redirect to another webpage? (58 answers) Closed 3 years ago.

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.


There's no need for jQuery.

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


Use:

window.location.replace(...)

See this Stack Overflow question for more information:

How do I redirect to another webpage?

Or perhaps it was this you remember:

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


This is easier:

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

Or

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


I think you are looking for:

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

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


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

See this answer here for a full explanation: How do I redirect to another webpage?


You can use just JavaScript:

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

精彩评论

暂无评论...
验证码 换一张
取 消