[英]Change the folder name of URL with a text link?
我有一个包含两种语言内容的站点,它们的文件名都相同,但是存储在不同的文件夹中:/ EN /和/ ZH /。
我希望有一个文本链接,允许单击它并更改URL的文件夹名称。
就像点击文本链接“ ZH”一样,它会将网址更改为:
来自=>“ http://example.com/GroupA/EN/index.asp ”
到=> /ZH/index.asp”
我到处搜索,发现如下脚本:
脚本:
$(function() {
$(".flag").click(function(e) {
e.preventDefault();
var to = $(this).attr("href").substring(1); //removes the hash value # (#en will become 'en')
var from = jQuery.url.segment(-2);
var url = from.replace('/' + from + '/', '/' + to + '/');
document.location = url;
});
});
身体:
<a id="flags" href="#en" class="flag">English</a>
但是,当我尝试上述脚本时,它只会在URL末尾添加“ #en”,例如http://example.com/GroupA/EN/index.asp#en
$(function() {
$(".flag").click(function(e) {
e.preventDefault();
var to = $(this).attr("href").substring(1); //removes the hash value # (#en will become 'en')
var url = window.location.hostname + "/GroupA/"+to.toUpperCase()+"/index.asp"
window.location.assign(url);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.