gpt4 book ai didi

Javascript startsWith 不适用于 iPhone 和 IE

转载 作者:行者123 更新时间:2023-11-30 11:31:56 25 4
gpt4 key购买 nike

我仅在移动版 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com