1

I have some code that checks the user's language. If the user is German they get sent to "de.html" otherwise they're sent to "en.html". There is also a string that checks if the user is going to the editor, ('/?edit'), and if so nothing happens. This code works fine, however, it doesn't work in IE. Any ideas?

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";
    }
  }
Andrew Bone
  • 7,092
  • 2
  • 18
  • 33
Billy Berg
  • 49
  • 4
  • Possible duplicate of [ie does not support 'includes' method](https://stackoverflow.com/questions/31221341/ie-does-not-support-includes-method) – Andreas May 25 '18 at 08:59
  • The problem should have been easy to fix because the console would have told you what the problem is. – Andreas May 25 '18 at 08:59

1 Answers1

1

includes() is not supported in Internet Explorer (or Opera). You need to use indexOf() instead of includes()

if(window.location.href.indexOf('/?edit') === -1)
//check if `window.location.href` do not include `/?edit`
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62