【问题标题】:Equivalent to googlechrome://myurl.com for Safari相当于 google chrome://url.com for Safari
【发布时间】:2018-11-22 16:52:42
【问题描述】:

我的 web 应用程序存在一些问题,如果用户单击 Facebook 应用程序中的链接,它将使用它自己的浏览器/webview,但需要使用 Safari 或 Chrome 才能运行该页面。

在研究 (this issue) 时,我发现您可以在 Android 设备上使用 googlechrome://navigate?url=example.com 打开 chrome,以及 googlechrome:/ /myurl.com 从 iOS 也可以打开 Chrome,但如果用户的设备是 iOS,我需要一种方法来打开 Safari。

有办法吗?

Ps.:用户在 Facebook 中点击的链接会转到一个登陆页面,在这个页面中有一个 webapp 的按钮。当用户单击此按钮时,我将打开 Chrome/Safari。

提前致谢!

【问题讨论】:

    标签: ios web mobile mobile-safari


    【解决方案1】:

    SO 有一些类似主题的答案。类似于

    NSString *yourUrl = @"http://yourURL";
    SFSafariViewController *svc= [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString: yourUrl]];
    [self presentViewController:svc animated:YES completion:nil];
    

    在 Swift 中是这样的

    let yourUrl = "http://www.yourURL.com";
    let svc = SFSafariViewController.init(url: URL);
    svc.delegate = self
    present(svc, animated: true);
    

    应该可以。

    如果您使用的是 Javascript,请查看 Force link to open in mobile safari from a web app with javascript

    看来你需要做类似的事情

    HTML:

    <div id="foz" data-href="http://www.google.fi">Google</div>
    

    JS:

    document.getElementById("foz").addEventListener("click", function(evt) {
        var a = document.createElement('a');
        a.setAttribute("href", this.getAttribute("data-href"));
        a.setAttribute("target", "_blank");
    
        var dispatch = document.createEvent("HTMLEvents");
        dispatch.initEvent("click", true, true);
        a.dispatchEvent(dispatch);
    }, false);
    

    在 (http://www.hakoniemi.net/labs/linkkitesti.html) 测试它

    来源:

    Open links in Safari instead of UIWebVIew?

    How to force links to open in iOS Safari?

    https://www.hackingwithswift.com/example-code/uikit/how-to-use-sfsafariviewcontroller-to-show-web-pages-in-your-app

    Force link to open in mobile safari from a web app with javascript

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多