【发布时间】:2021-07-16 12:41:54
【问题描述】:
这是我最后一个问题的延伸。我在JS上写了一个函数
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;
}
}
但是当我从英文浏览器进入时,它只是保持重定向,几秒钟后链接开始看起来像这样:https://www.site/en/en/en/en/en/en/en/en/。 url只能更换一次吗?
【问题讨论】:
-
你在uri中没有找到
'lang'并且lang不是ru-RU,因此你不断地重定向。 -
如果我从俄罗斯浏览器
ru-RU进入站点,什么都不会发生,因为函数只会在lang != ru-RU时执行。 -
是的,但如果你是英文用户,你不是俄罗斯用户,因此你会不断重定向。
-
@luk2302 我该如何解决这个问题?我没听明白:
you do not find 'lang' in the uri and the lang is not ru-RU
标签: javascript url redirect hyperlink uri