开发者

Get the largest embed/object in a page i.e. largest dimensions

开发者 https://www.devze.com 2023-01-25 06:29 出处:网络
Could someone show me how to get th largest embed or object in an web page which has the l开发者_开发问答argest dimensions. I need to be able to do this without any JS libraries.

Could someone show me how to get th largest embed or object in an web page which has the l开发者_开发问答argest dimensions. I need to be able to do this without any JS libraries.

Thanks.


Supposing you have every <embed> element in an <object> (working example):

function largestFlash() {
  var all = document.getElementsByTagName("object");
  var largest, largest_dimension = 0;
  for (var i = all.length; i--;) {
    var width  = parseInt(all[i].width,  10);
    var height = parseInt(all[i].height, 10);
    var dimension = width * height;
    if (dimension > largest_dimension) {
      largest = all[i];
      largest_dimension = dimension;
    }
  }
  return largest;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消