[英]Redirection if language of browser is not russian
This is extended my last question.这是我最后一个问题的延伸。 I wrote a function on JS
我在JS上写了一个function
const uri = window.location;
const lang = window.navigator.language;
if( uri.href.indexOf('lang') < 0) {
if (lang != 'ru-RU'){
const re = "https://www.site/";
const url = window.location.href;
const newstr = url.replace(re, 'https://www.site/en/');
window.location.href = newstr;
}
}
But when I'm entering from english browser, it's just keeping redirecting and in few seconds link starts looking like this: https://www.site/en/en/en/en/en/en/en/en/
.但是当我从英文浏览器进入时,它只是保持重定向,几秒钟后链接开始看起来像这样:
https://www.site/en/en/en/en/en/en/en/en/
。 Can url be replaced only one time? url可以只更换一次吗?
<script>
const uri = window.location;
const lang = window.navigator.language;
if( uri.href.indexOf('lang') < 0) {
if (lang != 'ru-RU'){
eng = window.location.href.includes('https://www.fashiondance.in.ua/en/');
console.log(eng);
if (eng == false){
const re = "https://www.fashiondance.in.ua/";
const url = window.location.href;
const newstr = url.replace(re, 'https://www.fashiondance.in.ua/en/');
window.location.href = newstr;
}
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.