简体   繁体   English

使用网络技术在iOS应用内的浏览器中打开链接

[英]Open link in browser inside iOS app with web techniques

Let's assume someone is running a web app directly inside a simple iOS app with UIWebView. 假设有人使用UIWebView在简单的iOS应用程序中直接运行Web应用程序。 It it possible to open a external website link inside the browser (Safari Mobile) with web techniques like JavaScript? 是否可以使用JavaScript之类的Web技术在浏览器(Safari Mobile)中打开外部网站链接? If yes, how could it be done? 如果是,该怎么办?

To open a URL programmatically: 要以编程方式打开URL:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.com"];

As far as your WebView, you can use your WebViewDelegate to catch and inspect any hyperlinks the user selects. 对于WebView,您可以使用WebViewDelegate捕获并检查用户选择的任何超链接。 For example: 例如:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *urlPath = [request URL];
    if (navigationType == UIWebViewNavigationTypeLinkClicked)
    {
        if ([[urlPath scheme] hasPrefix:@"http"]))
        {
            [[UIApplication sharedApplication] openURL:urlPath];
            return (NO);
        }

    }

    return (YES);
}

This should open any hyperlink click in browser app. 这应该打开在浏览器应用程序中单击的任何超链接。

You can also create a custom protocol, see Android / iOS - Custom URI / Protocol Handling , and catch those in this same delegate handler by checking the [url scheme] property. 您还可以创建自定义协议,请参阅Android / iOS-自定义URI /协议处理 ,并通过检查[url scheme]属性来捕获同一委托处理程序中的协议 This will allow you to explicitly do something with javascript. 这将允许您显式地使用javascript做某事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS应用程序,链接以在浏览器中打开网站,网站中的链接关闭浏览器 - iOS app, link to open website in browser, link in website closes browser 启用移动网络应用以在用户移动默认浏览器中打开链接,而不是在应用内部打开 - Enable mobile web app to open a link in user mobile default browser instead of opening inside the app iOS - 来自 web 浏览器的链接在 iOS 应用程序中打开一个应用程序,尽管它应该重定向到 Z2567A5EC9705EB7AC2DZE98403 - iOS - Link from web browser opens an app in iOS app although it should be redirected to web browser 来自iOS浏览器的网页链接中的打开位置应用 - Open location app from webpage link from ios browser 在浏览器或本机应用程序中正确打开Facebook页面链接IOS cordova - Open facebook page link in browser or native app correctly IOS cordova 从打包为原生iOS应用的Web应用打开外部链接 - Open external link from web app packaged as native iOS app iOS Facebook App浏览器 - 强制链接在Safari中打开 - iOS Facebook App browser - force link to open in Safari 如何创建我的应用程序链接以在 iOS Swift 的浏览器中打开 - How to create my app link to open in browser in iOS Swift 使Web链接在iOS设备上打开App Store - Make a web link open App Store on iOS devices iOS-通过Web应用程序中的链接打开Microsoft标记阅读器 - iOS - Open Microsoft tag reader from link in web app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM