简体   繁体   English

如何使用 HTML/JS 屏蔽广告?

[英]How to block ads with HTML/JS?

I have a site ( forum.tdp4teambattle.com ) and recently, I started getting ads in the footer.我有一个网站( forum.tdp4teambattle.com ),最近,我开始在页脚中添加广告。 I looked in the footer and there is no code for the ad.我查看了页脚,没有广告代码。 I'm thinking they put it in another file and specified it to a certain div ID.我认为他们将它放在另一个文件中并将其指定为某个 div ID。 What code in HTML or JavaScript can I use to hide the ad so others don't see it?我可以使用 HTML 或 JavaScript 中的哪些代码来隐藏广告,让其他人看不到它?

Here is the ad image: http://is.mixmarket.biz/images/um/95480.gif it is 468x60 (maybe you can give me a code to block images of that specific size from showing up).这是广告图片: http : //is.mixmarket.biz/images/um/95480.gif它是 468x60(也许你可以给我一个代码来阻止显示特定尺寸的图像)。

Edit, solved: if anybody was using "listbb.ru" or "getbb.ru", here is the solution.编辑,解决:如果有人使用“listbb.ru”或“getbb.ru”,这里是解决方案。 You'll need to view source on your index page and do CTRL+F.您需要在索引页面上查看源代码并按 CTRL+F。 Search for "mix", or "market" or similar.搜索“混合”或“市场”或类似内容。 You will see something along the lines of "mix_block_{identifier}".您将看到类似“mix_block_{identifier}”的内容。 To remove it, you'll need to navigate to ACP>Styles>Templates>{Theme}>Overall_header.html> find要删除它,您需要导航到 ACP>Styles>Templates>{Theme}>Overall_header.html> 找到

</head>

and before, enter:在此之前,输入:

<style>
#mix_block_1294937123 {
display: none;
}
</style>

The answer above is wrong.上面的答案是错误的。 For solving the ad's youself the chunk of code doing it is:为了自己解决广告,执行此操作的代码块是:

    <table border="0" cellspacing="0" cellpadding="0">
<tbody><tr>
<td>

<div id="mix_block_1294937123"><div id="mix_block_1294937123_1016" style="width:468px;height:60px;position: relative;"><a href="http://ucl.mixmarket.biz/uni/clk.php?id=1294878201&amp;zid=1294937123&amp;s=9019&amp;tt=08310735" target="blank"><img src="http://is.mixmarket.biz/images/um/95480.gif" width="468" height="60" border="0" alt=""></a></div><script type="text/javascript" src="http://udata.mixmarket.biz/uss/stat/?mid=1294887383&amp;id=1294937123&amp;tt=1472614515"></script><img src="http://mixmarket.biz/t.php?uid=1294929468&amp;r=http%3A//stackoverflow.com/questions/39240278/block-ads-with-html-js&amp;t=1472614515" width="1" height="1"></div>
<script type="text/javascript">
document.write('<scr' + 'ipt language="javascript" type="text/javascript" src="http://1294937123.us.mixmarket.biz/uni/us/1294937123/?div=mix_block_1294937123&r=' + escape(document.referrer) + '&rnd=' + Math.round(Math.random() * 100000) + '" charset="windows-1251"><' + '/scr' + 'ipt>');
</script><script language="javascript" type="text/javascript" src="http://1294937123.us.mixmarket.biz/uni/us/1294937123/?div=mix_block_1294937123&amp;r=http%3A//stackoverflow.com/questions/39240278/block-ads-with-html-js&amp;rnd=39740" charset="windows-1251"></script>
</td></tr></tbody></table>

So if you have access to the css pick a div and do因此,如果您可以访问 css,请选择一个 div 并执行

Display: none;

following code removes ads with undesired pictures and blocking elements that appear above the web page以下代码删除了出现在网页上方的带有不想要的图片和阻止元素的广告

(function removeAdvertisementAndBlockingElements () {
    $('.inRek').remove();
    $('.mgbox').remove();
    
    Array.from(document.getElementsByTagName("img")).forEach(function (e) {
        if (!e.src.includes(window.location.host)) {
            e.remove()
        }
    });    
    
    Array.from(document.getElementsByTagName("div")).forEach(function (e) {
        var currentZIndex = parseInt(document.defaultView.getComputedStyle(e, null).zIndex);
        if (currentZIndex > 999) {
            console.log(parseInt(currentZIndex));
            e.remove()
        }
    });
})();

Most of the ads are from google ad word.大多数广告来自谷歌广告词。 So there are inserted into a page by javascript.所以有通过javascript插入到页面中。 If you want to remove all ads only by inspecting it manually and remove it.如果您只想通过手动检查并删除它来删除所有广告。

The other thing what you can do is, to do an inspect element on the ad block by right-click and select the option inspect element in chrome that opens a small panel in the bottom section of your browser and set the block's CSS property (on right-hand side) as display:none;您可以做的另一件事是,通过右键单击广告块上的检查元素并选择 chrome 中的检查元素选项,这会在浏览器底部打开一个小面板并设置块的 CSS 属性(在右侧)作为显示:无;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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