Web pages and native apps jump to each other

Source: Internet
Author: User

In today's mobile apps, it's often necessary to show a Web page in the app, and often the Web page needs to be redirected back to the native app page for more page reuse.

Here is a way to determine if a jump is needed by intercepting a tag to jump ahead of time.

Here's how:

Android:
1Mwebview.getsettings (). setdomstorageenabled (true);2Mwebview.getsettings (). setdatabaseenabled (true);3Mwebview.getsettings (). setjavascriptenabled (true);4 mwebview.loadurl (URL);5Mwebview.setwebviewclient (Newwebviewclient () {6 @Override7              Public Booleanshouldoverrideurlloading (WebView view, String URL) {8                 //Add judgment code here, according to the URL to determine whether you need to jump to the native page or continue to jump to the page9 //view.loadurl (URL);Ten                     return true;//return True to end this monitoring, no need to broadcast again One                 } A});

Ios:

The controller where the UIWebView is located needs to implement Uiwebviewdelegate

Here's the code:

1- (void) Viewdidload {2 [Super Viewdidload];3Self.thewebview.Delegate= self;//Note: You need to set a delegate here4Nsurl *url = [Nsurl urlwithstring:@"http://www.baidu.com"];5Nsurlrequest *request =[Nsurlrequest Requestwithurl:url];6 [Self.thewebview loadrequest:request];7 }8 9-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (Nsurlrequest *Request Navigationtype: (Uiwebviewnavigationtype) Navigationtype {Ten     //determines whether the click One     if(Navigationtype = =uiwebviewnavigationtypelinkclicked) A     { -Nsurl *url =[Request URL]; -         //Add a judgment statement here, determine the URL of the page, whether you need to continue to jump, or use the native page the         returnNO;//return no, end page jump, if you want to continue to jump, need to return Yes -     } -     returnYES;//Continue page Jump - }

Web pages and native apps jump to each other

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.