【问题标题】:Problem opening a page in different UIWebViews using Javascript使用 Javascript 在不同的 UIWebViews 中打开页面时出现问题
【发布时间】:2010-07-28 16:10:36
【问题描述】:

我有一个 ipad 应用程序,其大部分功能是一个网络应用程序。 UI 只是加载页面的三个 UIWebView。每个被点击的链接都会被拦截,并且我在 URL 中有一个名为“iPadTarget”的请求变量。

前:http://www.somedomain.com/blah.asp?iPadTarget=2

上面的代码会在第二个 webview 中打开,因为 iPadTarget=2。

以下是完成此操作的代码:

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

    //Extract the value from request variable 'iPadTarget' in url string.
    NSString *test = [url query];
    int index = [test rangeOfString:@"iPadTarget="].location;   
    int target = index + 11;
    char c = [test characterAtIndex:target];
    NSLog(@"%c",c);

    if (navigationType == UIWebViewNavigationTypeLinkClicked || navigationType == UIWebViewNavigationTypeFormSubmitted || navigationType == UIWebViewNavigationTypeOther) {
        if (c == '1') {
            [viewOne loadRequest:request];
            return NO;
        } else if (c == '2') {
            [viewTwo loadRequest:request];
            return NO;
        } else if (c == '3') {
            [viewThree loadRequest:request];
            return NO;
        }
    } 
    return YES;
}

我的问题是:我有一个表单,按钮中有一个 onclick 事件:

<button onclick='window.open("someotherpage.asp?iPadTarget=2");window.open("someotherpage.asp?iPadTarget=3");'>Button</button>

该代码应该在第二个和第三个 UIWebView 中打开相同的页面。但是,它什么也不做,当我查看控制台输出时,它会无限打印 char c。

抱歉这个冗长的问题,我将不胜感激!

【问题讨论】:

    标签: javascript objective-c ipad uiwebview


    【解决方案1】:

    你确定这只是第一个UIWebView的代表吗?

    无论您做什么,都包含一些更详细的日志记录。即

    NSLog(@"request for webview %x, url=%@", ... );
    

    还有

    NSLog(@"returning NO because ...");
    

    找出循环的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-24
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 2021-06-07
      相关资源
      最近更新 更多