【问题标题】:Detecting user language in IE在 IE 中检测用户语言
【发布时间】:2018-11-04 14:54:50
【问题描述】:

我有一些检查用户语言的代码。如果用户是德国人,他们会被发送到“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";
    }
  }

【问题讨论】:

标签: javascript internet-explorer web


【解决方案1】:

includes() 在 Internet Explorer(或 Opera)中不受支持。您需要使用indexOf() 而不是includes()

if(window.location.href.indexOf('/?edit') === -1)
//check if `window.location.href` do not include `/?edit`

【讨论】:

  • 现在的 Opera 不是基于 Blink 构建的吗?
  • @AndrewBone 旧版本
猜你喜欢
  • 2014-12-05
  • 2017-01-06
  • 1970-01-01
  • 1970-01-01
  • 2018-07-29
  • 1970-01-01
  • 1970-01-01
  • 2011-12-30
  • 1970-01-01
相关资源
最近更新 更多