ios - Open a WKWebview target="_blank" link in Safari -
i trying hybrid ios app uses swift , wkwebviews open link has target="_blank" or if url contains http://, https://, or mailto: in mobile safari.
from this answer code.
func webview(webview: wkwebview!, createwebviewwithconfiguration configuration: wkwebviewconfiguration!, fornavigationaction navigationaction: wknavigationaction!, windowfeatures: wkwindowfeatures!) -> wkwebview! { if navigationaction.targetframe == nil { webview.loadrequest(navigationaction.request) } return nil } first, doesn't me. second, want open in new window. , found code supposed that...
if let requesturl = nsurl(string: "http://www.isecurityplus.com") { uiapplication.sharedapplication().openurl(requesturl) } how put these 2 , them work? need add viewcontroller declaration make work?
in (from here)
override func loadview() { super.loadview() self.webview.navigationdelegate = self self.webview.uidelegate = self //must have } then add function (from here, additions)...
func webview(webview: wkwebview, createwebviewwithconfiguration configuration: wkwebviewconfiguration, fornavigationaction navigationaction: wknavigationaction, windowfeatures: wkwindowfeatures) -> wkwebview? { if navigationaction.targetframe == nil { var url = navigationaction.request.url if url.description.lowercasestring.rangeofstring("http://") != nil || url.description.lowercasestring.rangeofstring("https://") != nil || url.description.lowercasestring.rangeofstring("mailto:") != nil { uiapplication.sharedapplication().openurl(url) } } return nil }
Comments
Post a Comment