本文介绍了Cordova(PhoneGap)和iFrames的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎每个人都知道愚蠢的一点,但在PhoneGap中不允许你在你的应用程序中使用iFrame。有许多修复,但它们要么是旧版本的PhoneGap,要么不起作用或导致其他问题。以下是我到目前为止所尝试的内容:

It seems everyone knows about the dumb little but in PhoneGap that doesn't allow you to have iFrames in your application. There are a number of fixes out there but they are either for legacy versions of PhoneGap, don't work or cause other issues. Here is what I have tried so far:


似乎没有上班。以下是我要完成的事情:

Nothing seems to work. Here is what I'm trying to accomplish:


  1. 来自vimeo(iframe)的视频嵌入留在app,externalhosts:vimeo.com a。 vimeocdn.com b.vimeocdn.com

  2. 所有其他链接出去野生动物园

这里是我的应用程序详细信息:

Here are my app details:

ios 5.1.1 | Cordova 1.7.0 | JqueryMobile | Jquery 1.7.1

ios 5.1.1 | Cordova 1.7.0 | JqueryMobile | Jquery 1.7.1

推荐答案

我有一个示例应用程序确实打开了应用程序内的Vimeo视频,但在Safari中打开了其他网址。

I have a sample application here which does open the Vimeo video inside the app but opens the other urls in Safari.

我更改了MainViewController.m中的以下功能

I changed the below function in MainViewController.m

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = [request URL];
    NSString *host = [request.URL host];

    if(host != NULL || host != nil){
        if ([host rangeOfString:@"vimeo.co"].location != NSNotFound) {
            return YES;
        }else{
            if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
                [[UIApplication sharedApplication] openURL:url];
                return NO;
            }
            else {
                return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
            }
        }
    }

    return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}

这篇关于Cordova(PhoneGap)和iFrames的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 01:18
查看更多