shlomikalfa Posted September 30, 2008 Share Posted September 30, 2008 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 !!! Quote Link to comment Share on other sites More sharing options...
shlomikalfa Posted September 30, 2008 Author Share Posted September 30, 2008 No one has any idea what so ever as to both of my questions ??? Quote Link to comment Share on other sites More sharing options...
shlomikalfa Posted October 3, 2008 Author Share Posted October 3, 2008 wow... amazing response.... Quote Link to comment Share on other sites More sharing options...
Flames Posted October 3, 2008 Share Posted October 3, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.