Block Ads with Javascript?

  • 1
  • Question
  • Updated 4 years ago
How to block ads? lets say the ads i want to block is http://foo.com/bla2.gif?.
Photo of lynx pravoka

lynx pravoka

  • 14 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 1
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Block ads??
Can't you simply refrain from publishing ads in your app?
Photo of lynx pravoka

lynx pravoka

  • 14 Posts
  • 0 Reply Likes
No, the ads i want to block is ads from other sites that use inject javascript to show the ads. can i block it with javascript like popular adblock? just add the domain and the path of js. and it will block it. ex. http://exmaple.com/example.js
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
You can.
- Define the strings you want removed in an array
- Fetch the code page code with ajax
- Loop through your array and remove the strings using regular expressions
- Insert the remaining code into the body element

Note:
1. You should be aware that this might be illegal
2. You should be aware that the original site owner may not like this
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@lynx,
Phonegap is not a webserver or a webbrowser. If you are opening a webpage, you can use the whitelist plugin to mark the domains and servers that are allowed.

Jesse