views:

23

answers:

1

Hi, I want to grab the image src on a product page in a e commerce website.

I'm writing this as a bookmarklet, so I'd like the code to work universally as possible.

I've noticed that there are only two reoccurring factors in the product image tag among top e-commerce websites (amazon, bestbuy ect.): border=0 and 180<width&height<400. So how could I write a selector that would give me the srcof the first img element on the page with no border and width & height between 180 and 400 px? Or is there a better way of doing this?

P.S. since I'm trying to keep the bookmarklet as light as possible, I don't want to use any libraries (jquery, yui etc)

A: 

I don't feel like I fully understand your question, but here I go anyways!

Do you mean something like...

function findYouImg() {
   var imgs = document.getElementsByTagName('img');
   for(var i=0; i<imgs.length; i++) {
      if(imgs[i].border=='' && imgs[i].width>180 && imgs[i].height<400 ) {
         return imgs[i];
      }
   }
}

Or are you refering to external CSS properties when you speak of border, width and height?

LeguRi