1

There's this site that has an image I want to replace. Just like the scripts that replace the background of a page, like Google.

In the html, it's in img scr. How do I replace that specific source on the page with another source so every time I visit that page, it displays the image I want instead of the one that's normally there?

jonsca
  • 10,218
  • 26
  • 54
  • 62
Absolyn
  • 11
  • 1
  • 1
  • 4

3 Answers3

4

A browser extension can accomplish this for you. I am familiar with how to do this with Requestly which my friend has made.

As an example I demonstrate how you would replace the Google logo image with Bing logo image with a simple rule:

screenshot of rule config in Requestly

and then on reloading the page after enabling the rule:

bing logo on google homepage

Param Aggarwal
  • 2,459
  • 2
  • 17
  • 15
1

If you just want to change it for yourself, Greasemonkey is ideal. It lets you run a script (Kerin provides a starting point) every time you visit the page. See these Greasemonkey tutorials.

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
0

EDIT: It appears that you want to replace an image on a site that is not yours. If you do not have legitimate access to the site's webserver or CMS system, there is nothing you can do. I'm leaving the rest of my post below just in case I have misinterpreted:


I'm assuming that you want to do this in Javascript, as you tagged your post with "Script." Other script languages exist, of course, but only Javascript really has a meaningful installed base.

First you need to assign the image an ID, something like:

<img src="/images/cat.png" id="mypicture">

Then, inside your Javascript, you can alter the image's source like so:

document.getElementById('mypicture').src = "/images/dog.png";

You can take this technique pretty far, even adding stuff to the image tag like:

<img src="/images/cat.png" id="mypicture" onClick="document.getElementById('mypicture').src = '/images/dog.png';">
Winfield Trail
  • 5,535
  • 2
  • 27
  • 43
  • I can't assign an ID to the image, since I can't edit another website's html. – Absolyn Jun 27 '11 at 03:34
  • This isn't changing the image dynamically, is it? it changes it in a specific way only once. – Tamer Shlash Jun 27 '11 at 03:34
  • Reddy, if it is another website's HTML then you will **not** be able to make changes that other users can see under any circumstances. – Winfield Trail Jun 27 '11 at 03:35
  • @Reddy: you can't change other websites, it not possible! we are talking about how to make it in your own pages. – Tamer Shlash Jun 27 '11 at 03:36
  • That's the thing, I just want it for me to see that image differently, not for everyone. I don't want to edit the HTML itself, I'm very well aware that you can't do that. I just want a script to change it from my view. – Absolyn Jun 27 '11 at 03:36
  • Does the image have a NAME attribute, or is it inside a DIV with an ID? – Winfield Trail Jun 27 '11 at 04:36