Javascript启动时没有在iPhone和IE上运行

时间:2017-08-28 15:28:14

标签: javascript internet-explorer safari

我仅在移动版Safari和IE上收到以下错误。

TypeError: undefined is not a function

违规代码是:

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

这在Chrome和Firefox中非常有效。任何想法为什么Safari& IE不喜欢它吗?

1 个答案:

答案 0 :(得分:2)

您可以添加以下polyfill

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