iOS modifies WebView background transparency and iOS calling the foreground JS method

Source: Internet
Author: User

The H5 page in WebView that encounters iOS on the job needs to be transparent to show the webview background color. With H5 own transparency CSS style or JS control background color and transparency can not hit the desired effect, and finally through the iOS set WebView body color and transparency to achieve, the specific code is as follows:

-(void) Webviewdidfinishload: (UIWebView *) webview{        [WebView Stringbyevaluatingjavascriptfromstring:@ "document.getelementsbytagname (' body ') [0]. Style.background= ' Rgba (0,0,0,0) '"];}

The H5 page is then transparent and displays the WebView background color. Android has not yet researched how to set the background of the H5 page in WebView. There is time to study it later.

Incidentally, the way iOS calls the foreground page JS method:

First, you add a JS method to the page and return a value, for example:

//See more iOS call MethodsfunctionGetparameterforios (parameter) {varResult= ""; varCity=sessionstorage.getitem ("usedCarCity001"); varIs_type=sessionstorage.getitem ("usedCarCertification002"); if(is_type== "true") {Is_type= 0; }Else{Is_type= 1; }    // City    if(parameter== "City") {result=City ; }    //Is_type    if(parameter== "Certification") {result=Is_type; }    returnresult;}

Then, in iOS, the method is called when the webview load starts or ends, for example:

-(void) Webviewdidstartload: (UIWebView *) webview{        *certification = [WebView Stringbyevaluatingjavascriptfromstring:@ "getparameterforios (' certification ')"];        }

The resulting return value is assigned to the variable for use.

Big God do not spray, younger brother just encounter this problem, do a record only ...

iOS modifies WebView background transparency and iOS calling the foreground JS method

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.