[英]Block specific images so they won't load
我希望我的擴展程序阻止加載兩個圖像。
我認為可以通過在content.js中使用以下內容輕松實現
$("#rated-image").remove(); //id of one image
$(".blur-mask").remove(); //class of other image
並將run_at
設置為document_start
。 但這似乎無能為力。
使用document_end
它會執行content.js,因此代碼不會出現問題。
我無法想象有什么辦法做到這一點,谷歌也沒有給出答案。
所以我想要的是,當頁面開始加載時,圖像將在有機會加載之前被刪除。
我不確定您要做什么。 如果您只需要設置display就可以了:none!important並專門針對只希望使用css隱藏圖像的位置,那么它會比javascript循環便宜。
我還包括了javascript(jQuery)解決方案。
也許如果您可以闡明您要嘗試做的事情,那么我可以指導您找到最佳解決方案。
$(document).ready(function(){ // this deletes all images from the dom $("img").each(function(){ $(this).remove(); }); });
.i-want-images-hidden-here img { display: none !important; /* this only targets imgs inside said container. You can remove .i-want-images-hidden-here before img to hide every image on your page */ }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="i-want-images-hidden-here"> <img src="http://placehold.it/350x150" /> <img src="http://placehold.it/350x150" /> <img src="http://placehold.it/350x150" /> <img src="http://placehold.it/350x150" /> <img src="http://placehold.it/350x150" /> <img src="http://placehold.it/350x150" /> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.