1

I want to block images in a website which is often unimportant ads uploaded to their server or host.

Using inspect element I noticed the all these images was named with ad-[some number].jpg.

I can’t use any extensions in my browser so is it possible to do something like that using the “hosts” file or any local way.

I have tried ad-*.jpg but it doesnt make any sense.

2
  • 3
    Use Ad block software in browser. In hosts file you can block entire hostname (to be resolved) Commented Apr 21, 2017 at 13:11
  • i want it to be global for all users with all browers.
    – Omar mah
    Commented Apr 21, 2017 at 14:29

3 Answers 3

1

I want to block images in a website....so how could i do that using hosts file or any local way.

The Hosts file won't work for you. It blocks everything served by a server.

The HOSTS file enables you to change the IP address your computer uses to connect to certain hosts. For example the following entry:

www.example.com       127.0.0.1

will cause your computer to direct all connections targeting the Internet host www.example.com to 127.0.0.1.

However, what you're trying to do is block requests for resources on the Internet host, such as www.example.com/ads/somead.jpg, without blocking other content on the host. This cannot be done with the Hosts file; it's all or nothing.

I can't use any extensions

Bummer.

It's no good that the solution to your problem is to use browser extensions like AdBlock Plus. That's really the best approach when trying to implement something on your local machine to block unwanted ads.

If you happen to have control of the router that serves your network, it may have some options for blocking unwanted content at the network level.

1
  • Your HOSTS example is backwards: the format is address on the left, one or possibly several hostname(s) on the right. But even if corrected, as you say it's not a solution to this Q. Commented Jun 29 at 3:25
0

I know this is quite late to the game but Proxomitron, though no longer supported, author passed away, rewrites html on the fly to eliminate ads and unwanted content. You can even replace code with your own. Minorly functional with ASP and PHP pages.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Jun 29 at 6:42
-2

You can do it with hosts file by mapping a hostname to localhost but you need to know what server's hostname is requested to display these ads. I would suggest to use Ad block software which would do the job better.

Anyhow if you manage to get ad server hostname or ip you just have to do as I said above :

/etc/hosts:

ad_server's_hostname localhost
ad_server's_ip       localhost
4
  • 1
    This will block entire server, not only the images! Commented Apr 21, 2017 at 13:37
  • You mean server that hold the website Omar mah is navigating on or the server that provides ads ?
    – jehutyy
    Commented Apr 21, 2017 at 13:40
  • It can be. You want to read some news site w/o seeing ads Commented Apr 21, 2017 at 13:42
  • 1
    yeah guys I only need to block images for example: www.example.com/images/ad-num.jpg i need to block images from that directory which hold the ad prefix.
    – Omar mah
    Commented Apr 21, 2017 at 14:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .