问题
I need help. Anybody knows why I can't consistently load URLs into iframes within phonegap/cordova iOS? I noticed that some pages simply refuse to load inside an iframe while others will load just fine. I also can't seem to get SSL based sites to load. Examples:
<iframe src="http://ucla.edu"></iframe> //loads correctly
<iframe src="http://google.com"></iframe> //refuses to load
<iframe src="http://www.ufrj.br"></iframe> //loads correctly
<iframe src="http://192.168.20.95"></iframe> //loads correctly (this a local server I have inside my work network)
<iframe src="https://192.168.30.15"></iframe> //refuses to load (this also a local server but with a valid ssl cert (signed by startcom/startSSL)
I added stay-in-webview and access origin tags to config.xml (I can load SOME external pages in the iframe) but not sure why this behavior is not consistent. The Mac I'm using to develop can load all these properly.
I am new to this so I am trying things out to wrap my head around the basics before start "porting" my old webApps into mobile platforms. My dev systems has: Lion Cordova 2.5 xCode 4.6
Any help is welcome. Thanks!
回答1:
I think I got it. I will post it here in the case someone else falls in the same misconception I did.
Looking at the response headers in my regular desktop browser I noticed that the pages which won't load in the mobile app iframe have the X-Frame-Options: SAMEORIGIN
set in their response headers.
This option tells the web-browser NOT to load that page in a frame unless the window belongs to the same origin. Since my iframe doesn't qualify, the page won't load. https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options
I had also (mis)understood the goal of the config.xml whilelisting: That whitelisting is places the app can visit. It has little to do with what can be received by the app. My bad.
I will try working with the childbrowser plugin for cordova and hope for better results. https://github.com/macdonst/phonegap-plugins/tree/master/Android/ChildBrowser
-rod
来源:https://stackoverflow.com/questions/15438054/cant-properly-load-external-urls-in-an-iframe-with-cordova-ios