Q:

Javascript startsWith not working on iPhone and IE

I'm getting the following error ONLY on mobile Safari and IE.
TypeError: undefined is not a function

The offending code is:
if(window.location.origin.startsWith(shopAddress + "/account/login")  && 
sessionStorage.getItem('loggedIn') == "true")

This works beautifully in Chrome and Firefox. Any idea why Safari & IE don't like it?

A:

you can add following polyfill
if(!String.prototype.startsWith) {
  String.prototype.startsWith = function(searchString, position){
    return this.substr(position || 0, searchString.length) === searchString;
  };
}

