Take the largest image on the site given the url

Given the url, how can I draw the largest image (in terms of image sizes) on the site? I use it to act as the best representation of site thumbnails.

Similar to the first thumbnail when sharing a URL on Facebook:

http://www.facebook.com/share.php?u=my_website_url

Thumbnail image on Facebook in div:

<div class="UIThumbPager_Thumbs"> 

Current code (using Javascript and jQuery):

 else if (item.link) historyHtml += '<a href=' + item.link + ' class="image" target="_blank"><img src="*SITE THUMBNAIL HERE*" width="111px"></a>'; 

Please note that the user will be registered on Facebook and will be able to access this thumbnail of the site.

+4
javascript jquery html css
source share
2 answers

You cannot do this on the client side (i.e. using JavaScript) due to restrictions between domains. First you need to load the contents of the URL on the back. See Here: http://en.wikipedia.org/wiki/Same_origin_policy

+3
source share

"Largest" image in image sizes or sizes? You will have to parse the URL code, extract all the images and get the size. If you mean image sizes, you can do it using JavaScript (create a new image from the img source and use img.width and img.height ), but for the file size you will probably end up loading all the images in the define which one is the biggest.

+1
source share

All Articles