我仅在移动Safari和IE上收到以下错误。
TypeError: undefined is not a function
令人反感的代码是:
if(window.location.origin.startsWith(shopAddress + "/account/login") &&
sessionStorage.getItem('loggedIn') == "true")
在Chrome和Firefox中可以很好地工作。知道为什么Safari和IE不喜欢它吗?
最佳答案
您可以添加以下polyfill
if(!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position){
return this.substr(position || 0, searchString.length) === searchString;
};
}