我仅在移动版 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;
};
}
关于Javascript startsWith 不适用于 iPhone 和 IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45922506/