开发者

How can i block images from certain site with javascript?

开发者 https://www.devze.com 2023-03-08 15:32 出处:网络
I think this can be done with js.. Let\'s say i want to block loading images from example.com or even with a single image path?

I think this can be done with js..

Let's say i want to block loading images from example.com or even with a single image path?

I prefer the first variant. can i do this?

Example:

if a image is displayed in html with http://example.com/filepath, don't allow to display images from that dom开发者_StackOverflow中文版ain or even the file path.


Probably not. You can add JavaScript at the bottom of the page or using the onLoad event but at that time, the browser might have already started the requests to load the images (it can start with that as soon as it reads the image URL).

There simply is guarantee that your JavaScript executes before the highly-optimized URL loading of the browser kicks in.

You also can't load the other page in an iframe thanks to Same Origin Policy.

Instead, you should configure a proxy like Privoxy or use something like AdBlock.


With Firefox you can Greasemonkey to do exactly this with all the power of Javascript.


If you don't mind using jquery

on body tag

<body onload="remove()">

javascript(jquery)

function remove()
{
    $('img').each(function() {
        if(this.src.search('somehostname') != -1)
            $(this).remove();
    });
}

Not sure if they fired image request or not ,but they won't come in your sight for sure

0

精彩评论

暂无评论...
验证码 换一张
取 消