My website has a lot of links and I'm trying to replace all thea href
targets_top
with_blank
. How can I implement this functionality using JavaScript?
It will find all the_top
in my page and replace them with_blank
I tried the following:
// const string = document.getElementsByTagName('a')[0].innerHTML const string = document.querySelector("_top"); //获取字符串 var newstring = string.replace(/_top/, '_blank'); //尝试在整个页面中替换字符串 const myTimeout = setTimeout(selecteAd, 2000); //设置延时以确保网页完全加载
renew:
Data comes from Google AdSense'sasync
code. (Found similar solutions in other parts of Stackoverflow, but I still can't replace. How to get DIV child elements using JavaScript)
Use querySelectorAll