Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

iphone - How can I open an iframe in a phonegap/cordova app running on IOS?

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.

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.

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.

Steps taken:

  1. I added the second site to the "ExternalHosts" array in the Cordova.plist file.
  2. I created a config.xml file next to the index.html file in the /www directory, according to the PhoneGap/Cordova documentation (https://build.phonegap.com/docs/config-xml).
  3. I added a <preference name="stay-in-webview" value="true" /> tag to the config.xml file as a child of the main <widget> tag.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

2 things changed from the time that iframes were broken to when they started working:

  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.com" height="100%" width="100%" frameborder="0"></iframe>').appendTo('body'); .

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...