This is the blog for getting Idea regarding PHP, Magento, jQuery and JavaScript for Customization.

Saturday 6 June 2015

jQuery : Check image exist or not on location


Hello Friends,

Sometimes we need to check, Is file is exist or not on particular location?

So, for this using below method we can check the file is exist or not !

jQuery
<script type="text/javascript">

function imageExists(url, callback) {
    var img = new Image();
    img.onload = function() { callback(true); };
    img.onerror = function() { callback(false); };
    img.src = url;
}

function onload(id) /*This function will use while Mouseover event */
{
         var imageUrl = "Image File URL";
         imageExists(imageUrl, function(exists) {
if(exists==true){
/*Something Code here*/
}else{
                        /*Something Code here*/
                }
        });
}

</script>
,

No comments:

Post a Comment