Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block ads from appearing in android webview

I am creating a webview which loads some sites. I want to block the ads in these sites from appearing in the webview. I want it for both http and https sites. Actually i am able to do it for http sites by javascript injection.But this method will not work for https. Is there any way to do this?

like image 377
jubin Avatar asked Nov 01 '22 09:11

jubin


1 Answers

Access the website(www.adwaresite.com) using some proxy server that you own. You can create one very easily in Google app engine.

Prefetch the html of www.adwaresite.com on your server and add the base tag of www.adwaresite.com at the top of the html and send it to the android webview over http

<head>
<base href="http://www.w3schools.com/images/" target="_blank">
</head>

<body>
<img src="stickman.gif" width="24" height="39" alt="Stickman">
<a href="http://www.w3schools.com">W3Schools</a>
</body>

Note the base tag in above code. Base tag helps to add domain to the relative urls inside html. So instead of picking the domain from the address bar , it uses this base domain specified at the top

like image 164
HimalayanCoder Avatar answered Nov 11 '22 19:11

HimalayanCoder