我的代码:
const checkoutUrl = 'https://example.com/checkout/*'
window.onload = startup()
function startup() {
if (window.location.href == checkoutUrl) {
// DO something
//call a function
}
}但实际的URL是:
'https://example.com/checkout/?x=0&spni=Random_Number&ID=Some_Random_Number_Always'所以(window.location.href == checkoutUrl)没有起作用。checkoutUrl的正确格式是什么
发布于 2020-04-03 04:48:37
检查字符串是否以checkoutUrl开头。为此,您需要从checkoutUrl中删除*,因为没有通配符匹配。
const checkoutUrl = 'https://example.com/checkout/';
if (window.location.href.startsWith(checkoutUrl))https://stackoverflow.com/questions/61000828
复制相似问题