Get thumbnails from a Web page when sharing to a friend's circle

Source: Internet
Author: User

Scene: Do a mobile Web page, when the scan to enter the page needs to determine whether users choose to share the circle of friends, if you want to share a friend circle, you need to find out the page class=article_content of a div below all the IMG pictures, if the picture proportion appropriate (aspect scale), Then set it to the thumbnail display on the left side of the share.

functionGetThumbnail () {varArrayimgs = []; $("Div.article_content img"). each (function () {        //Alert ($ (this). attr ("src"));Arrayimgs.push ($ ( This). attr ("src"));    }); varwidth, height, i; varResult= "";  for(i = 0; i < arrayimgs.length; i++)    {        //Image Address        varImg_url =Arrayimgs.pop (); //Creating Objects        varIMG =NewImage (); //change the src of the pictureIMG.SRC =Img_url; //determine if there is a cache        if(img.complete) {//PrintAlert (' from:complete:width: ' + img.width + ', Height: ' + img.height + '; Result: "+result); }Else{                 //load Complete ExecutionImg.onload =function(){                        //PrintAlert (' from:onload:width: ' + img.width + ', Height: ' + img.height + '; Result: "+result);        }; }        if(Img.width/img.height > 0.6 && img.height/img.width < 1.4) {result=Img_url;  Break; }    }    returnresult;}

Get thumbnails from a Web page when sharing to a friend's circle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.