Select 所有基于 href 的锚标签并更改它

Select all anchor tags based on href and Change it

我有一个关于根据 HREF 更改 URL 锚标签的问题。

我对select所有锚标签所做的是这样的:

var anchortags = document.querySelectorAll("a[href*='secureloan.asim.no']");

有了这个 select 所有引用 secureloan.asim.no

的锚标签

我还想要在用户点击链接时更改链接(我想删除一个参数)

URL 的示例可以是:

Example URL:
www.secureloan.asim.no/oasis/index.html#/no/asim?lang=nb-no&product=lev&lanekilde=&campaigncode(etc....).

我想从参数中删除 "lanekilde="。我正在使用此代码:

String(document.location.href).replace("&lanekilde=", "");

这给了我正确的 URL 但我如何在网站上的所有用户点击它时更改它。

到目前为止我编写的代码:

var anchortags= document.querySelectorAll("a[href*='secureloan.remember.no']");
String(document.location.href).replace("&lanekilde=", "");

谢谢你:)

PS: 否 Jquery 请!
PS:如果有人有不同的想法,我会使用标签管理器

您只需遍历节点集并依次更改每个节点集:

var anchortags = document.querySelectorAll("a[href*='secureloan.asim.no']");
anchortags.forEach(function(tag) {
    tag.href = tag.href.replace('&lanekilde=', '');
});