如何在Javascript或jQuery中重定向URL [英] How to redirect URL in Javascript or jQuery
问题描述
有人可以帮助我理解如何在Javascript或jQuery中使用PHP的简单重定向后执行此操作吗?
Can some one please help me to understand how to do this following PHP's simple redirection in either Javascript or jQuery?
如果客户端想要重定向 www.clientsite.com/bbc
到 http://www.bbc.com/
然后用PHP我只会做 bbc文件夹并在其中创建一个 index.php
文件并添加以下行:
If the client wanted to redirect the www.clientsite.com/bbc
to http://www.bbc.com/
then in PHP I would just make the "bbc" folder and create an index.php
file in it and add these lines:
<?php
header("Location: http://www.bbc.com/");
?>
所以我的问题是,如何重定向 www.clientsite.com/ bbc
到 BBC
页面,或者如果它是 www.clientsite.com/food
那么到使用Javascript或jQuery Food Network
等等?非常感谢你提前!
So my question is, how can I redirect www.clientsite.com/bbc
to BBC
page, or if it's www.clientsite.com/food
then to Food Network
and so on with either Javascript or jQuery? Thank you very much in advance!
更新:
谢谢大家的帮助!由于某种原因, window.location.href
没有重定向我的页面,所以我最终使用了 window.location.replace
。并且发现这些页面非常有用:
Thank you everyone for your help! For some reason the window.location.href
wasn't redirecting my page, so I ended up using the window.location.replace
. And found these pages very helpful:
- http://www.yourhowto.net/how-to-redirect-url-in-javascript-or-jquery
- http://www.rapidtables.com/web/dev /javascript-redirect.htm
- http://www.yourhowto.net/how-to-redirect-url-in-javascript-or-jquery
- http://www.rapidtables.com/web/dev/javascript-redirect.htm
推荐答案
JS重定向与nojs后备。
JS redirect with nojs fallback.
代码:
<script>
window.location.href = "YOUR-URL";
</script>
<noscript>
<META http-equiv="refresh" content="0;URL=YOUR-URL">
</noscript>
这篇关于如何在Javascript或jQuery中重定向URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!