如何在IOS上运行的phonegap / cordova应用程序中打开iframe? [英] How can I open an iframe in a phonegap/cordova app running on IOS?

查看:216
本文介绍了如何在IOS上运行的phonegap / cordova应用程序中打开iframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个webapp,我使用PhoneGap / Cordova安装在iOS和Android。在应用程序的某一点,我有一个iframe从第二个服务器加载内容。

I have a webapp that I'm using with PhoneGap/Cordova to install in iOS and Android. At one point in the app I have an iframe that loads content from a second server.

当我从浏览器运行应用程序时,一切都按预期工作 - iframe在同一页面中打开,并从第二个网站加载内容。

When I run the app from a browser, everything works as expected - the iframe opens in the same page and loads the content from the second site.

当我使用Cordova在iPhone模拟器上运行webapp时,iframe打开时,iOS切换到Safari并将我的应用程序放在后台。

When I run the webapp on an iPhone simulator using Cordova, when the iframe opens, iOS switches over to Safari and puts my app in the background.

采取的步骤:


  1. 我将第二个网站添加到Cordova.plist文件中的ExternalHosts li>
  2. 根据PhoneGap / Cordova文档( https://build.phonegap.com/docs/config-xml )。

  3. 我添加了< preference name = stay-in-webviewvalue =true/>标签添加到config.xml文件中作为主< widget>标签。

我的怀疑是,它不读/使用config.xml文件,但可能有其他的东西...

My suspicion is that it is not reading/using the config.xml file, but there could be something else... Does anyone have any ideas what I might be doing wrong?

推荐答案

添加一个InAppBrowser来替换我之前使用的iframe ,我最终再次尝试了一个iframe,iframe现在可以正常工作,而不需要跳转到手机的浏览器,就像以前一样,iframe在iOS和Android上都能一直工作。

After adding an InAppBrowser in place of the iframe I was using before, I eventually tried an iframe again, and the iframe now works without jumping over to the phone's browser, as it was doing before, and the iframe works consistently in both iOS and Android.


  1. 我升级到Cordova 2.5

  2. 我开始使用jquery动态创建/添加iframe到页面,而不是像之前一样,取消隐藏已经存在的iframe:

  1. I upgraded to Cordova 2.5
  2. I started dynamically creating/adding the iframe to the page using jquery, rather than just unhiding an already-existing iframe, as I was doing initially:

$('< iframe src =whatever.comheight =100%width =100%frameborder =0>< / iframe& ).appendTo('body');

$('<iframe src="whatever.com" height="100%" width="100%" frameborder="0"></iframe>').appendTo('body'); .

我没有打扰检查固定iframe的#1或#2问题(我猜它是#1),但我想我会发布,它是可能得到iframes工作与PhoneGap / Cordova应用程序,以防万一有人遇到同样的问题。

I didn't bother checking whether it was #1 or #2 that fixed the iframe issue (I'm guessing it's #1), but I thought I would post that it IS possible to get iframes working with a PhoneGap/Cordova app, in case someone else runs into the same problem.

这篇关于如何在IOS上运行的phonegap / cordova应用程序中打开iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆