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";
    }
  }
2
  • Possible duplicate of ie does not support 'includes' method Commented May 25, 2018 at 8:59
  • The problem should have been easy to fix because the console would have told you what the problem is. Commented May 25, 2018 at 8:59

1 Answer 1

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`
Sign up to request clarification or add additional context in comments.

2 Comments

Isn't Opera built on Blink these days?
@AndrewBone for older versions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.