Click here to Skip to main content
14,697,231 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using JavaScript here is my goal:
I want to make a chrome extension that does this: finds the string value of all img src attributes in the documemt, then stores them in variables, then uses a comparison operator to check whether the each one contains a certain word, then if it does, replace the image with another image.

What I have tried:

I have tried things to get the img src value like this:
var im = document.getquerySelector('img').src;

But that did not work. Because this is a chrome extension I cant use getElementById because this needs to work on all web pages and not just ones that I make and assign IDs to. Please help. Or tell me if there is a simpler way to do this. Thanks!
Updated 19-Aug-20 6:38am
Sandeep Mewara 19-Aug-20 11:22am
Curious - whats the intent of doing it?
landocss 19-Aug-20 11:28am
A blocker for annoying images.

1 solution

This should get you move ahead, believe most of what you seek is here. You would mostly need to adjust the image search/match logic to your requirement: Chrome Extension Tutorial — Replace Images in Any Website with Pikachu[^]

Check out!
landocss 19-Aug-20 11:41am
Thank you, but I would like to replace only certain images on websites, not all images, only the ones that have certain words in the src attribute.
Sandeep Mewara 19-Aug-20 11:48am
Go ahead and see how the code is and where you can fit in your search in it. Try out.
landocss 19-Aug-20 11:51am
Ok, I will do, but I have no idea how to get the value for the img src attribute.
Sandeep Mewara 19-Aug-20 12:03pm
landocss 19-Aug-20 12:12pm
ok, thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900