[PhoneGap] Iframes

899 views
Skip to first unread message

Paul G. Hunt

unread,
May 22, 2010, 10:30:12 PM5/22/10
to phonegap
Hi all.

Phonegap seems to send the user to Safari if there is an iframe in the
app. Past discussions bring up the following fix:

Change this code
-----

// Check to see if the URL request is for the App URL.
// If it is not, then launch using Safari
NSString* urlHost = [url host];
NSString* appHost = [appURL host];
NSRange range = [urlHost rangeOfString:appHost
options:NSCaseInsensitiveSearch];
if (range.location == NSNotFound)
[[UIApplication sharedApplication] openURL:url];

NSString * jsCallBack = nil;
NSArray * parts = [urlString
componentsSeparatedByString:@":"];

-----
To this

// Check to see if the URL request is for the App URL.
// If it is not, then launch using Safari
NSString* urlHost = [url host];
NSString* appHost = [appURL host];
NSRange range = [urlHost rangeOfString:appHost
options:NSCaseInsensitiveSearch];
/*
* We don't have a PhoneGap request, it could be file
or something else
*/
if (range.location == NSNotFound) {
/* [[UIApplication sharedApplication]
openURL:url]; */
}

}

NSString * jsCallBack = nil;
NSArray * parts = [urlString
componentsSeparatedByString:@":"];


--------

How would one do this in 0.9.0? I'm presently developing only for
iPhone OS, if that matters.

Thanks in advance for any insights.

Best,

Paul Hunt

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Giacomo Balli

unread,
May 26, 2010, 3:22:11 PM5/26/10
to phonegap
you can disable opening safari on links but as far as I know iframe is
not supported.

> For more options, visit this group athttp://groups.google.com/group/phonegap?hl=en?hl=en

Matthew David

unread,
May 26, 2010, 3:49:25 PM5/26/10
to Giacomo Balli, phonegap
Yep, you are right. Bit of a bummer :(

Matthew David
Make IT Happen
P: (920) 389-1212
E: mda...@matthewdavid.ws
B: Web 3.0 Blog 
L: Linked In 


D. Rimron

unread,
May 27, 2010, 4:14:23 AM5/27/10
to phon...@googlegroups.com
On 26/05/2010 20:22, Giacomo Balli wrote:
> you can disable opening safari on links but as far as I know iframe is
> not supported.
>
Not actually true. (On the iPhone, at least)You can set the iframe to a
local "blank.html" sourcefile (remember, your Phonegap app can hold
multiple HTML pages in it) and then use Javascript to populate the
iFrame itself, although not from a straight HTTP://.html file, rather
via XHR/JS/App Logic. It's the lack of src=file that causes the browser
to pop up, as the default action URL handler for HTTP requests.

-Dx

Roberto Ugo

unread,
May 30, 2010, 3:48:28 PM5/30/10
to phonegap
I'm using 0.9.0 and faced the same problem, but solved doing this
litle hack in phonegapDelegate.m
I was using Tab Bars, so when I changed the last else in the code so
it doesn't open Safari, it didn't opened the Tab bar as well... so I
changed this in the shouldStartLoadWithRequest function (added this
else if after the first if)

....

else if ([[url scheme] isEqualToString:@"http"])
{
//NSLog(@"File URL %@", [url description]);
return YES;
}

....

now iframe works and also the tab bar and all javascript calls.

r


On May 23, 3:30 am, "Paul G. Hunt" <gee.em...@gmail.com> wrote:
> Hi all.
>
> Phonegap seems to send the user to Safari if there is aniframein the
> For more options, visit this group athttp://groups.google.com/group/phonegap?hl=en?hl=en

Ricky

unread,
May 8, 2011, 10:38:04 PM5/8/11
to Roberto Ugo, phon...@googlegroups.com
I found this thread from searching on Google. I want to mention that
checking the url inside delegate.m would cause all the other "non-
iframe" links to load within the phonegap app.

I haven't figured out a solution that lets you both load an iframe src
naturally (don't let safari pop-up) and keep regular links clickable
(i.e. open safari.app or ChildBrowser).

Will let you guys know if I find anything interesting. Maybe there's a
way to recognize that a request comes from an explicit link?

Ricky

unread,
May 9, 2011, 4:49:50 PM5/9/11
to phonegap
In case anyone is curious, here is the updated snippet.

else if ([url isFileURL] ||
[[url scheme] isEqualToString:@"http"] ||
[[url scheme] isEqualToString:@"https"])
{
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSLog(@"PhoneGapDelegate::shouldStartLoadWithRequest: User
clicked. Regular handler. %@", url);
[[UIApplication sharedApplication] openURL:url];
return NO;
} else {
NSLog(@"PhoneGapDelegate::shouldStartLoadWithRequest: Received
file/http/https URL %@", url);
return YES;
}
}

Note: If you use jquery mobile, there's a problem with the iframe
reloading properly with changePage (e.g. embedded youtube videos won't
reply properly when you come back to a cached page). But this should
get iframes to work for now.

vesters

unread,
Jun 20, 2011, 8:25:24 AM6/20/11
to phon...@googlegroups.com
I have found another solution to this problem on this thread


The solution is to add the domain in PhoneGap.plist under External Hosts.

This was fine by me, cause I know what domains I wan't to allow to be shown in an iframe..

Enjoy

vesters

unread,
Jun 20, 2011, 5:06:37 AM6/20/11
to phonegap
Hi.

I'm looking to solve this problem, and your solution seems fine for my
needs.

Only thing is that I'm sort of a PhoneGap-rookie, and I can't seem to
find the place where I need to add your code.

If you could reveal a little more detail, it would be much
appreciated.

Thanks so far.
Reply all
Reply to author
Forward
0 new messages