Jump to content

Pictures, Is it a working picture link or not ?!


shlomikalfa

Recommended Posts

is there any way i can find out if a picture link is actually working or not by JS ?

 

==>>  I mean, i have this web-site which is suppose to show images users upload, but some of the images are deleted / are of bad url location thus they won't show... i want to know if there is any way to recognize the fact they aren't showing and display a different picture instead in that case.

 

==>>  Also i would like to know why wouldn't that picture show in my site:

http://ia.media-imdb.com/images/M/MV5BMTIzNzc5MDk3OV5BMl5BanBnXkFtZTcwMzc3Mjc1MQ@@._V1._SX94_SY139_.jpg

It is placed as: (HTML-wise)

<img src="http://ia.media-imdb.com/images/M/MV5BMTIzNzc5MDk3OV5BMl5BanBnXkFtZTcwMzc3Mjc1MQ@@._V1._SX94_SY139_.jpg" border="0" width="138" height="182">

 

PLEASE HELP :)

 

Thanks in advance !!!

did you try using google, im gonna guess you didn't...

after about 1 minute i managed to find 2 codes, which you might want to try.

Will give an alert message if it exists or doesnt exist

<script language="JavaScript"><!-
function testImage(URL) {
    var tester=new Image();
    tester.onLoad=isGood;
    tester.onError=isBad;
    tester.src=URL;
}

function isGood() {
    alert('That image exists!');   <---- if it exists change this line to whatever you want
}

function isBad() {
    alert('That image does no exist!');
}
//--></script>

 

OR

Will show another picture instead, so you could use a picture which said image not found or something.

function ImageTest(URL) {
var
MyImage = new Image();
I = 0;

MyImage.onerror = DoesntExists;
MyImage.src = URL;

if(I > 0){
return('<your another picture link>');
}

function DoesntExists(){
I++;
}

return(URL);
} 

 

hope it helps

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.