Swift:在特定的浏览器标签中打开URL? [英] Swift: open URL in a specific browser tab?

查看:76
本文介绍了Swift:在特定的浏览器标签中打开URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JavaScript,您可以在特定的浏览器标签中打开URL.

With JavaScript, you can open a URL in a specific browser tab.

您如何通过iOS应用程序使用Swift完成相同的操作,即在Safari/Chrome中的特定标签中打开URL.

How do you accomplish the same thing with Swift from an iOS app, i.e., open URL in Safari/Chrome in a specific tab.

UIApplication 打开功能没有不会列出有关 options 参数的信息,似乎可以让您指定用于打开URL的命名标签.

The UIApplication open function doesn't list information about the options parameter, which seems like it might let you specify a named tab in which to open the URL.

推荐答案

这就是我在 Google Chrome浏览器中打开链接的方式:

This is how I open links in Google Chrome:

var newLink: String = "http://www.apple.com"
newLink = link.replacingOccurrences(of: "http://", with: "googlechrome://")
if UIApplication.sharedApplication().canOpenURL(NSURL(string: newLink)!) {
UIApplication.sharedApplication().openURL(NSURL(string: newLink)!)
} else {
    let alertController = UIAlertController(title: "Sorry", message: "Google Chrome app is not installed", preferredStyle: .Alert)
    let okAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
    alertController.addAction(okAction)
    self.presentViewController(alertController, animated: true, completion: nil)
}

Opera Mini :

opera://open-url?url=http://

Opera Touch :

touch-https://

Firefox :

firefox://open-url?url=http://

海豚:

dolphin://

勇敢:

brave://open-url?url=http://

这篇关于Swift:在特定的浏览器标签中打开URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆