使用JavaScript,您可以在特定的浏览器选项卡中打开URL。
您如何通过iOS应用程序使用Swift完成同一件事,即在Safari / Chrome中打开特定标签中的URL。
在UIApplication 开放的功能没有列出有关的信息options参数,这似乎像它可能让你指定要在其中打开URL命名的标签。
这就是我在Google Chrome浏览器中打开链接的方式:
var newLink: String = "http://www.apple.com"
newLink = link.stringByReplacingOccurrencesOfString("http://", withString: "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)
}
Run Code Online (Sandbox Code Playgroud)
Opera Mini:
opera://open-url?url=http://
Run Code Online (Sandbox Code Playgroud)
火狐:
firefox://open-url?url=http://
Run Code Online (Sandbox Code Playgroud)
海豚:
dolphin://
Run Code Online (Sandbox Code Playgroud)
勇敢:
brave://open-url?url=http://
Run Code Online (Sandbox Code Playgroud)
将 url 的协议详细信息(HTTP 或 HTTPS)更改为 googlechrome,应用程序将在 Chrome 中打开该链接:
let sUrl = "googlechrome://www.google.com"
UIApplication.shared.openURL(NSURL(string: sUrl) as! URL)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3719 次 |
| 最近记录: |