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?
Asked
Active
Viewed 5,225 times
5
-
Why does your strategy for http sites not work for https pages? – ksasq Nov 30 '13 at 18:14
-
https will not allow javascript injection because of its security features @ksasq – jubin Dec 02 '13 at 09:56
-
1How are you doing this javascript injection? – ksasq Dec 02 '13 at 10:23
-
i used the method given here http://stackoverflow.com/questions/8200945/how-to-get-html-content-from-a-webview along with the script i needed to inject @ksasq – jubin Dec 02 '13 at 11:50
-
The best answer can be found at http://stackoverflow.com/questions/24547446/android-block-ads-in-webview/39152846#39152846 – Soren Stoutner Dec 23 '16 at 23:07
1 Answers
2
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

HimalayanCoder
- 9,630
- 6
- 59
- 60