phonegap 应用程序中的外部链接无法正常打开

人气:458 发布:2022-10-16 标签: cordova phonegap-build phonegap-plugins inappbrowser

问题描述

所以我有一个使用 Phonegap 2.9.0 并使用 PhonegapBuild 构建的 phonegap 项目.我在我的应用程序中有外部链接,我想打开应用程序或使用我的应用程序之外的默认设备浏览器.我对这两种解决方案都满意.今天我的应用程序在应用程序中打开链接,但它全屏显示,无法缩放,并且没有按钮可以返回应用程序...我试图找出解决方案几天,并在这里查看相同类型的问题,但没有任何效果.

So I have a phonegap project with Phonegap 2.9.0 and building with PhonegapBuild. I got external links in my app, that I would like to open inapp or using the default device browser outside of my app. I am ok for both solutions. Today my app open links inapp but it goes fullscreen, no zoom possible, and no button to come back in the app... I am trying to figure out a solution for days, and looking at the same kind of questions here but nothing work good.

有人可以清楚地解释一下所有这些东西是什么,以及不同的选择/参数是什么,因为我可以说这根本不清楚/容易!

Could somebody explain clearly what is all this stuff about, and what are the different choices/params because I can tell that it is not clear/easy at all!

第一季度:我首先会问:在文件 config.xml 中,phonegap 2.3.0 现在已弃用首选项stay-in-webview,对吗?所以这里没什么可期待的吗?

Q1 : I would start by asking : in the file config.xml the preference stay-in-webview is deprecated now for phonegap 2.3.0 right? So nothing to hope here?

第二季度:我阅读并尝试了很多关于带有 window.open 和目标系统/空白/自我的插件 InAppBrowser 但对我来说没有区别.我留在 InApp 但没用,因为没有导航按钮.我在这里错过了什么吗?

Q2 : I read and try a lot about the plugin InAppBrowser with window.open and target system / blank / self but no differences for me. I stay InApp but useless because no navigation buttons. Am I missing something here?

plugin name="InAppBrowser" value="CDVInAppBrowser"

推荐答案

我首先会问:在文件 config.xml 中,phonegap 2.3.0 现在已弃用偏好留在 webview,对吗?所以这里没什么可期待的吗?

I would start by asking : in the file config.xml the preference stay-in-webview is deprecated now for phonegap 2.3.0 right? So nothing to hope here?

没错.如果您使用的是 2.9 甚至不用担心这个设置

That's correct. Dont even worry about this setting if you are using 2.9

我阅读并尝试了很多关于带有 window.open 和目标系统/空白/自我的插件 InAppBrowser,但对我来说没有任何区别.我留在 InApp 但没用,因为没有导航按钮.我在这里遗漏了什么吗?

I read and try a lot about the plugin InAppBrowser with window.open and target system / blank / self but no differences for me. I stay InApp but useless because no navigation buttons. Am I missing something here?

我也遇到了一些问题,无法使其正常工作.他们的文档有点分散,需要全部阅读.这是我如何让它工作:

I had a few issues getting this to work as well. Their documentation is a bit scattered and need to read it all. Here is how I get it working:

确保您的每个页面中都有 <script src="phonegap.js"></script> 想要使用 inappbrowser您不需要在 config.xml 中包含插件标记.我很确定他们在 2.5 左右将 inappbrowser 包含在核心构建功能中.

要在 inappbrowser 中打开链接,请使用以下 javascript: Ensure you have <script src="phonegap.js"></script> in each of your pages that wants to use the inappbrowser You should NOT need to include a plug-in tag in your config.xml. I am pretty sure that around 2.5 they included inappbrowser in the core build functionality.

To open a link in the inappbrowser, use this javascript:

function openURL(urlString){
    myURL = encodeURI(urlString);
    window.open(myURL, '_blank');
}

这将在 inappbrowser 中打开传递的 URL.如果将 window.open(myURL, '_blank'); 更改为 window.open(myURL, '_system'); 它将在系统浏览器中打开传递的 URL.

This will open the passed URL in the inappbrowser. If you change window.open(myURL, '_blank'); to window.open(myURL, '_system'); it will open the passed URL in the system browser.

最后,您的项目点击如下所示:

Finally, your item clicks look like this:

<a href='#' onclick='openURL("http://www.urlyouwant")/>

或者您可以将事件列表器附加到对象上,但我认为您明白了.

Or you could attach event listiners to the object, but I think you get the point.

此外,InAppBrowser 有很多您可以附加到它的事件侦听器.如果您有兴趣,请查看文档

Additionally, the InAppBrowser has a lot of event listeners you can attach to it. Take a look at the documentation if you are interested in those.

重要!!!不要忘记第 1 步!

Important!!!! Do not forget step 1!

希望这会有所帮助.

766