码迷,mamicode.com
首页 > 移动开发 > 详细

APP分享抓取网页图片

时间:2015-04-09 19:29:35      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

var getShareImages = {
    defaultimg:"defaultimg.png",
    _allImgs:null,
    init:function(){
        getShareImages._allImgs = document.getElementsByTagName("img");
        if(getShareImages._allImgs.length == 0){                    
            return getShareImages.defaultimg;
        }else{
            return getShareImages.checkRepeat();
        }
    },
    _srcs:{},
    allImgs:[],
    checkRepeat:function(){
        var len = getShareImages._allImgs.length;
        for (var i = 0; i < len; i++) {
            var _img = getShareImages._allImgs[i];
              // 过滤掉不可以见的图片
              if(_img.style.display == ‘none‘ || _img.style.visibility == ‘hidden‘){
                  continue;
              }

              if(getShareImages._srcs[_img.src]){

              }else{
                  getShareImages._srcs[_img.src] = 1;
                  getShareImages.allImgs.push(_img);
              }
        };
        return getShareImages.checkCondition();

    },
    results:[],
    checkCondition:function(){
        var len = getShareImages.allImgs.length;
        var img;
        var loadedCount = 0;
        for (var i = 0; i < len && i < 10; i++) {
            img = getShareImages.allImgs[i];
            if(img.width >= 200 || img.height >= 200){
                loadedCount++;
                getShareImages.results.push(img);
                return img.src;
            } 
        };
        if(loadedCount == getShareImages.results.length){
            return getShareImages.defaultimg;
        }
    }
}
getShareImages.init();

 

APP分享抓取网页图片

标签:

原文地址:http://www.cnblogs.com/gzzfans/p/4410316.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!