简体   繁体   中英

How to open an URL with swift/cordova code triggered in HTML ? (by Javascript?)

I have a very sneaky problem. I'm using Cordova to embeded my web-app onto iOS app.

But we have external URL and with our technique, it's really painfull to open external URL. And Cordova plugins like InAppBrowser does not work (because our app is already use an inapp browser).

Goal : we want to open an external URL, from a HTML page, to the Safari navigator of the device.

Maybe with Javascript ? I thought about something like :

UIApplication.shared.open(url, options: [:], completionHandler: nil)

So maybe, we can add in MainViewController a command triggered by an HTML button who use Javascript to open the URL in Safari ?

Anyone have an idea ? Many thanks

check for canOpenURL then open

if let url = URL(string: "https://www.google.com"),
        UIApplication.shared.canOpenURL(url) {
            UIApplication.shared.open(url, options: [:])
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM