开发者

javascript bookmarklet to hide all images from current webpage?

i wanna create a simple bookmarklet that hides all images from the current website i'm browsing.

javascript:body.getElementsByTagName("img").style.visibility="hidden";

that's not wo开发者_开发知识库rking? i wonder what i'm doing wrong?

thank you for your help!


You need to iterate over the array-like object returned from document.getElementsByTagName, e.g.:

var imgs = document.getElementsByTagName("img");
for (var i = 0; i < imgs.length; i++) {
    imgs[i].style.visibility = "hidden";
}

Edit:

The complete bookmarklet URI:

javascript:(function(){var imgs=document.getElementsByTagName("img");for(var i=0;i<imgs.length;i++)imgs[i].style.visibility="hidden"}());


my problem is this image-banners over the complete page (not interesting). so i was not able to read any text (text is interesting).

set height to 0 or in this example to 60px

var imgs = document.getElementsByTagName("img");
for (var i = 0; i < imgs.length; i++) {
    imgs[i].style.height = "60px";
}

javascript:(function()%7Bvar%20imgs%20%3D%20document.getElementsByTagName(%22img%22)%3Bfor%20(var%20i%20%3D%200%3B%20i%20%3C%20imgs.length%3B%20i%2B%2B)%20%7Bimgs%5Bi%5D.style.height%20%3D%20%2260px%22%3B%7D%7D)()

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜