Advertisements Removal Script For Websites

Posted By : Mohit Sharma | 10-Jul-2018

Removing unwanted Advertisements from Website even when Adblock is disabled because of content visibility compromise.

For developers out there reading online content is a part of our life, at the same the monetizing the content is crucial for a website to generate advertisement revenue.

But, the problem occurs when some publishers really give you hard time to access the content by popping up the advertisements everywhere on the page. Most of these advertisements are iframe based meaning that published just pushes the iframe from their affiliate website. There is a solution to this problem.

By just very simple jQuery code we can eliminate the advertisements. The prerequisite here is jQuery since we will inject the jQuery code to remove the advertisements. But if jQuery is not being used on the page by default. Stil we can inject it using chrome console.

// Check if Jquery is being used on the website

 $().jquery; // This will print the version of jqery if jquery is available otherwise it'll console this error "Cannot read 
 property 'jquery' of undefined"

 

// If Jquery is not being used on the target page, Simply page below code on the chrome console. Open the chrome console and page the code below

var script = document.createElement('script');script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js";document.getElementsByTagName('head')[0].appendChild(script);
 
For Example, we are going to use:
https://www.javamadesoeasy.com/2015/12/what-is-default-initial-capacity-of_6.html // This site is filled with ads everywhere.
 

Now Simply paste below code the all the ads will be removed in an instance.

// remove all iframe ADS
$("iframe").each(function() { 
        $(this).attr('src',src);  
});
 

This being a very basic kind of ad blocker, with some common behaviors study of a website, we can develop the capability to remove all kinds of ads completely.

I hope this gives you some insight and usability of jQuery for manipulation websites behaviors and content.

About Author

Author Image
Mohit Sharma

Mohit is a bright Web App Developer and has good knowledge of Java.

Request for Proposal

Name is required

Comment is required

Sending message..