1

It's a same question like Open mobile Safari From a link in a webview.
The answer of above question mentioned that it is possible to open from Chrome.
Also, this question provides a solution, but not work in webview on iOS 8 above.

However, the goal I would like to achieve is that to open the mobile Safari by clicking an URL in webview of an app(It may be gmail client, whatsapp, facebook messengers..etc).

I would describe my user scenario to make my question more clear.


I have a website with a link of site A. Users may receive the URL of my website in gmail app, facebook messenger or whatsapp. When users clicked the URL of my website, the site will directly show in webview of the app. When the users click the link of site A, I hope it can open the site A in the mobile Safari instead of staying in the webview because I need the add to screen function provided by Safari so that users could add the site A to the home screen more conveniently.


There is no url-scheme like safari://xxx. Are there any JavaScript or HTML ways to achieve this purpose?
I have searched on the net, but could not find a working solution on iOS 8 above.
Any suggestions are appreciated. Thanks a lot!

Community
  • 1
  • 1
Calvin Jeng
  • 47
  • 1
  • 1
  • 7

1 Answers1

1

Yes it is.

Add a delegate to your webview and implement the following method :

  optional  func webView(_ webView: UIWebView,
shouldStartLoadWithRequest request: NSURLRequest,
     navigationType navigationType: UIWebViewNavigationType) -> Bool

as follow :

func webView(webView: UIWebView, request: NSURLRequest,navigationType: UIWebViewNavigationType) -> Bool {

 //Check if the URL is the one you want in mobile safari   
 if request.URL.absoluteString == THE_URL_TO_OPEN_IN_MOBILE_SAFARI {
        UIApplication.sharedApplication.openURL(request.URL)
        return false
    }else{
        return true
    }
}
CZ54
  • 5,488
  • 1
  • 24
  • 39
  • Thanks for your reply, this is not what I want. Sorry for my unclear description of my question. I have updated my question. Hope it is more clear. – Calvin Jeng May 12 '16 at 09:47
  • Oh, I see now what's your question is. I think is more an HTML/javascript question now :) – CZ54 May 12 '16 at 11:56