是否有办法使此脚本仅在URL中存在utm_campaign参数时执行?
function fillFormArea(){
const select = document.getElementById('property.cust_AreaOfInterest.value');
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString); //parse the query string
const country = urlParams.get('utm_campaign'); // Store the parsed area of interest
select.value = country; // fill the form with the area of interest
}
if (document.readyState === 'loading') { // Loading hasn't finished yet
document.addEventListener('DOMContentLoaded', fillFormArea)
}
else { // `DOMContentLoaded` has already fired
fillFormArea();
}
1条答案
按热度按时间0g0grzrc1#