javascript Cordova 3.0 - 在 iOS 的外部浏览器中打开链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17971811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 10:16:55  来源:igfitidea点击:

Cordova 3.0 - Open link in external browser in iOS

javascriptioscordova

提问by Splendiferous

How do you open links in the devices native browser when using Cordova 3.0 on iOS?

在 iOS 上使用 Cordova 3.0 时,如何在设备本机浏览器中打开链接?

People have suggested using window.open( url, "_system" )but this does not work in Cordova 3.0.

人们建议使用,window.open( url, "_system" )但这在 Cordova 3.0 中不起作用。

My Attempt

我的尝试

if( navigator.app ) // Android
    navigator.app.loadUrl( url, {openExternal:true} )
else // iOS and others
    window.open( url, "_system" ) // opens in the app, not in safari

Does anyone know of a solution that works with Cordova 3.0?
Thanks

有谁知道适用于 Cordova 3.0 的解决方案?
谢谢

回答by dannytenaglias

NOTE: to make window.open('somelink', '_system')to work you now need a device-level plugin, the inAppBrowser. Here are the installing instructions as of Cordova 3.0

注意:为了window.open('somelink', '_system')工作,您现在需要一个设备级插件,inAppBrowser。以下是 Cordova 3.0 的安装说明

From the Docs for 3.0:

来自 3.0 的文档:

As of version 3.0, Cordova implements device-level APIs as plugins. Use the CLI's plugin command, described in The Command-line Interface, to add or remove this feature for a project:

从 3.0 版开始,Cordova 将设备级 API 实现为插件。使用命令行界面中描述的 CLI 插件命令为项目添加或删除此功能:

$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
$ cordova plugin rm org.apache.cordova.core.inappbrowser

These commands apply to all targeted platforms, but modify the platform-specific configuration settings described below:

这些命令适用于所有目标平台,但修改如下所述的特定于平台的配置设置:

iOS (in config.xml)

iOS(在 config.xml 中)

<feature name="InAppBrowser">
    <param name="ios-package" value="CDVInAppBrowser" />
</feature>

I just tested this and it works.

我刚刚测试了这个并且它有效。

回答by gregmatys

install InAppBrowser plugin:

安装 InAppBrowser 插件:

$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
$ cordova plugin rm org.apache.cordova.core.inappbrowser

and execute the plugin in your .js file:

并在您的 .js 文件中执行插件:

//exec(successCallback, errorCallback, pluginName, pluginMethod, params)
cordova.exec(null, null, "InAppBrowser", "open", [url, "_system"]);