Javascript jQuery 位置 href
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7078660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery location href
提问by Benjamin
I remember there's a redirect function in jQuery.
我记得 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.
但究竟是什么?我不记得了,也无法使用 Google 搜索找到它。
回答by Dogbert
There's no need of jQuery.
不需要 jQuery。
window.location.href = 'http://example.com';
回答by Curt
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).attr('href',url);
回答by Joseph Marikle
This is easier:
这更容易:
location.href = 'http://address.com';
Or
或者
location.replace('http://address.com'); // <-- No history saved.
回答by totallyNotLizards
I think you are looking for:
我认为您正在寻找:
window.location = 'http://someUrl.com';
It's not jQuery; it's pure JavaScript.
它不是 jQuery;它是纯 JavaScript。
回答by Jamie Dixon
Ideally, you want to be using window.location.replace(...)
.
理想情况下,您希望使用window.location.replace(...)
.
See this answer here for a full explanation: How do I redirect to another webpage?
请在此处查看此答案以获取完整说明:如何重定向到另一个网页?
回答by RobB
You can use just JavaScript:
你可以只使用 JavaScript:
window.location = 'http://address.com';