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 !!!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.