[英]How do I replace all the blocked google ads (with an image) on my page instead of just the first one? Trouble with CSS selectors
我想用禮貌地要求將網站列入白名單的圖像替換所有被阻止的廣告(針對使用adblock的用戶)。
這段代碼根本不是我寫的,它是從一個我似乎無法再次追蹤的站點獲取的。 我有點不好意思在這里發布,但是我在看似簡單的修復上浪費了很多時間。
<script>
window.onload = function(){
setTimeout(function() {
var ad = document.querySelector("ins.adsbygoogle");
if (ad && ad.innerHTML.replace(/\s/g, "").length == 0) {
ad.style.cssText = 'display:block !important';
ad.innerHTML = '<img src="image here"></img>';
}
}, 2000);
};
</script>
我已經嘗試過這樣的事情:
var ad = document.querySelectorAll("ins.adsbygoogle");
但這似乎沒有幫助。
嘗試循環瀏覽廣告:
var ads = document.querySelectorAll("ins.adsbygoogle");
for (var ad in ads) {
if (ad.innerHTML.replace(/\s/g, "").length == 0) {
ad.style.cssText = 'display:block !important';
ad.innerHTML = '<img src="image here"></img>';
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.