简体   繁体   English

通过简单的WebView-App在本机浏览器中打开URL

[英]Open URL in native browser from simple WebView-App

I have an (native) app which just represents a simple WebView (iOS) that directs to a webpage. 我有一个(本机)应用程序,该应用程序仅表示一个定向到网页的简单WebView(iOS)。 Is it possible to open some URLs from that webpage with the native iOS browser (Safari)? 是否可以使用本机iOS浏览器(Safari)从该网页打开一些URL?

Following code does not work, but works great in an PhoneGap app (which also basically represents just a WebView): 以下代码不起作用,但在PhoneGap应用程序(基本上也只代表WebView)中很好用:

window.open(twitter_url, '_system');

You are goint o have to call back into the Native portion of code from your javascript and call something like this: 您可能需要从javascript中回调代码的本机部分,并调用如下代码:

NSURL *url = [ [ NSURL alloc ] initWithString: @"http://www.Google.com" ];

[[UIApplication sharedApplication] openURL:url];

You can get this call from javascript into your native code by overloading the function 您可以通过重载该函数来将此调用从javascript转换为您的本地代码

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

In the UIWebview Delegate. 在UIWebview委托中。 Then parse the load request and run the launch function above based on the response. 然后解析加载请求并根据响应运行上面的启动功能。 How you word that launch request is up to you. 您如何确定启动请求的字样取决于您。

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

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