使用HTML和Javascript将所有HTML链接转换为另一个URL

1 html javascript jquery

我正在尝试在字符串中获取网站主体部分中的所有HTML链接,并将其替换为另一个链接.

试过这样的事但是没有用:

var search = "https://www.cloudflare.com/5xx-error-landing?utm_source=error_footer";
var replacement = "https://example.com/";

document.body.innerHTML = document.body.innerHTML.split(search).join(replacement)
Run Code Online (Sandbox Code Playgroud)

其中" https://www.cloudflare.com/5xx-error-landing?utm_source=error_footer "是我要替换的链接," https://example.com/ "是我要替换的链接.

Nir*_*ana 5

这个怎么样:

$("[href='your link']").attr("href","new link");
Run Code Online (Sandbox Code Playgroud)