查询位置 href

我记得在 jQuery 中有一个重定向函数。

就像这样:

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

但是它到底是什么呢? 我不记得了,而且用谷歌搜索也找不到它。

502672 次浏览

There's no need for jQuery.

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

This is easier:

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

Or

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

You can use just JavaScript:

window.location = 'http://address.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;

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

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

I think you are looking for:

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

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