Javascript从#anchor重定向到单独的页面 [英] Javascript to redirect from #anchor to a separate page
本文介绍了Javascript从#anchor重定向到单独的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一组指向单个网页的#anchors链接,我希望能够顺利地转移到每个链接都有单独网页的模型。我希望旧链接继续使用重定向。
I have a set of links with #anchors pointing to a single webpage and I would like to smoothly move to a model with a separate webpage for each of those links. I want the old links to keep working using a redirect.
旧链接样式:
/all_products#A
/all_products#B
/all_products#C
新链接样式:
/products/A
/products/B
/products/C
我知道服务器在请求中没有收到#anchor名称,但Javascript可能会收到。
I know that the server does not receive the #anchor name in the request but Javascript might.
是否可以使用Javascript自动从/ all_products#A重定向到/ products / A. ?
JQuery没问题,无论如何都在网站上使用。
JQuery would be fine, it's being used on the site anyway.
推荐答案
我希望这可以帮助:)
var urlSplit = document.URL.split("#");
if (urlSplit[1]) {
location.href = "http://www.example.org" + "/" + urlSplit[1];
}
else {
location.href = "http://www.example.org";
}
这篇关于Javascript从#anchor重定向到单独的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文