regicidedelferoz Posted January 6, 2012 Share Posted January 6, 2012 good day everyone, hi can anybody here wanna help me? i want to replace missing images automatically on load of the page,. i got some code on the net but it doesn't work on IE,. here's the code,. for (var i=0; i<document.images.length; i++){ img = new Image(); img.src = document.images[i].src; if (img.height == 0) document.images[i].src = '<?php echo $livesitePath; ?>images/picnotavailable.jpg'; } here's another one that is not workingon IE,. $(window).load(function() { $('img').each(function() { if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0 || this.src=="") { // image was broken, replace with your new image this.src = '<?php echo $livesitePath; ?>images/picnotavailable.jpg'; } });}); Link to comment Share on other sites More sharing options...
thescientist Posted January 6, 2012 Share Posted January 6, 2012 are you trying to echo PHP from javascript? That won't work (IE or otherwise). By the time javascript is executed, PHP's window has long since passed. Perhaps you want to make an AJAX request or use a static link to fill in the gaps of missing images. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 6, 2012 Share Posted January 6, 2012 Check for Javascript errors in IE. Print out the values you're checking (height, etc) to verify the values. Link to comment Share on other sites More sharing options...
regicidedelferoz Posted January 7, 2012 Author Share Posted January 7, 2012 are you trying to echo PHP from javascript? That won't work (IE or otherwise). By the time javascript is executed, PHP's window has long since passed. Perhaps you want to make an AJAX request or use a static link to fill in the gaps of missing images. yes,. and it's working,. Check for Javascript errors in IE. Print out the values you're checking (height, etc) to verify the values. thanks for your reply,. got the right one,. $(window).load(function() { $('img').each(function() { if (!this.complete || this.naturalWidth == 0 || this.src=="") { // image was broken, replace with your new image this.src = '<?php echo $livesitePath; ?>images/picnotavailable.jpg'; } });}); this is the error i think typeof this.naturalWidth == "undefined" Link to comment Share on other sites More sharing options...
justsomeguy Posted January 9, 2012 Share Posted January 9, 2012 You should use parens when you're using the typeof operator: (typeof this.naturalWidth) == "undefined" Link to comment Share on other sites More sharing options...
thescientist Posted January 9, 2012 Share Posted January 9, 2012 yes,. and it's working,. is the page itself already a PHP page? That was not immediately obvious from your post. Link to comment Share on other sites More sharing options...
regicidedelferoz Posted January 12, 2012 Author Share Posted January 12, 2012 ignore the livesitePath, my problem is the jquery,. and now it's working fine,. anyways thank you guys,. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.