我想,如果用户正在访问分割窗口位置相应
xxxx.com will need to go to xxxx.com/langchoice.
2.xxxx.com/currentlang/test.php will need to go to xxxx.com/langchoice/test.php
根据郎选择下拉菜单并使用他们当前window.location的所以将用户重定向3
xxxx.com/test.php will need to go to xxxx.com/langchoice/test.php
我已经做了1和2,但不是特别满意我编码的方式,考虑到如果更多的话年龄可能会增加,我需要每次都添加一行...可以更好地重写吗?
var s = window.location.href;
if (s.indexOf(".php") !=-1)
{
if (s.indexOf("/en/") !=-1)
{
var location=window.location.href.replace("/en/","/"+evt.selectedItem+"/");
}
else if (s.indexOf("/gr/") !=-1)
{
var location=window.location.href.replace("/gr/","/"+evt.selectedItem+"/");
}
else if (s.indexOf("/it/") !=-1)
{
var location=window.location.href.replace("/it/","/"+evt.selectedItem+"/");
}
else
{
}
window.location.replace(location);
}
else
{
var location=window.location.href.replace("#","");
window.location.replace(location+evt.selectedItem);
}
您可能想要试用RegEx。 – malkassem
也许动态地在后端(php)中创建语言选择,每个语言版本的完整URL会自动 – fast