我有一些代码可以检查用户的语言。如果用户是德语,他们会被发送到" de.html"否则他们会被发送到" en.html"。还有一个字符串可以检查用户是否要访问编辑器('/?edit')
,如果没有,则不会发生任何事情。此代码工作正常,但它在IE中不起作用。有什么想法吗?
var lang = window.navigator.language;
var userLang = window.navigator.userLanguage;
if (!window.location.href.includes('/?edit')) {
if (lang == "de" || userLang == "de") {
window.location.href = window.location.href + "de";
} else {
window.location.href = window.location.href + "en";
}
}
答案 0 :(得分:1)
includes()
。您需要使用indexOf()
代替includes()
if(window.location.href.indexOf('/?edit') === -1)
//check if `window.location.href` do not include `/?edit`