简体   繁体   中英

URL Paramters carried between pages - how to stop tel: also?

I have this really basic script that changes all the links on my wordpress site to preserve the url param - I use it on wordpress landing pages for my business

    var queryString = new URL(window.location).search;
document.querySelectorAll("[href]").forEach(link => {
    var current = link.href;
    link.href = current + queryString;
});

Eg

website.com/?location=Australia

All links on the page will carry over the parameter to whatever href link my visitor clicks

/book-online/?location=Australia

/request-a-callback/?location=Australia

However this is obviously changing all my href links, and is changing my tel: links with it.

Is there a way I can make it only change https://?

My tel: links look like this

tel:0293 12329?location=Australia

I have had this code copied and pasted for ages, I know absolutely nothing about javascript and no idea where I found the above code, I've just used it for ages and it works as a quick and easy way for me to track a users progress through my landing pages.

Perhaps you could only do this if tel: is not in the href?

var queryString = new URL(window.location).search;
document.querySelectorAll("[href]").forEach(link => {
  var current = link.href;
  if (!current.includes("tel:")) {
    link.href = current + queryString;
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM