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