Images are not loaded in Ios:uiwebview (ie, the browser's common no-diagram mode)

Source: Internet
Author: User

Wrote about UIWebView not loading pictures, looked up a lot of information,

About JS, about OC, in StackOverflow and so did not find the right answer,

Finally feel that we should return to the traditional JS code,

Stringbyevaluatingjavascriptfromstring to invoke the JS method

JS Code:

var div_hide_css_id ="Ibrowser_div_hide_css";//-------------------have picture/no diagram----function Jshandlehideimage () {var i=0; var alldiv= document.getElementsByTagName ("DIV");  for(i; i<alldiv.length; i++) {var e=Alldiv[i]; var bg_image=E.style.backgroundimage; E.style.backgroundimage="None"; E.setattribute ("Bg_image", Bg_image); } var newcss=document.getElementById (div_hide_css_id); if(Newcss = =undefined) {Document.documentElement.innerHTML= document.documentelement.innerhtml+"<style id= '"+div_hide_css_id+"' >img{visibility:hidden;} </style>"; }    Else {        if(newcss.innerhtml = ="') {} newcss.innerhtml='Img{visibility:hidden;}'; }}function jshandleshowimage () {var i=0; var alldiv= document.getElementsByTagName ("DIV");  for(i; i<alldiv.length; i++) {var e=Alldiv[i]; var bg_image= E.getattribute ("Bg_image"); E.style.backgroundimage=Bg_image; } var newcss=document.getElementById (div_hide_css_id); if(newcss) {newcss.innerhtml='img{visibility:visibility;}'; }}

OC Code

if (// no picture) {    [WebView stringbyevaluatingjavascriptfromstring:@ "jshandlehideimage ()"];  } Else {    [webView stringbyevaluatingjavascriptfromstring:@ "jshandleshowimage () " ];  }

Images are not loaded in Ios:uiwebview (ie, the browser's common no-diagram mode)

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.