开发者

Problem opening a page in different UIWebViews using Javascript

I have an ipad app, with the majority of the functionality being a web application. The UI is just three UIWebViews that load the pages. Every link that is clicked is intercepted, and I have a request variable in the URL called "iPadTarget."

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

The above code would open in the second webview, because iPadTarget=2.

Here is the code that accomplishes this:

- (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 == UIWebViewNavigationTypeLin开发者_StackOverflow社区kClicked || 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;
}

My problem is this: I have a form with an onclick event in a button:

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

That code SHOULD open the same page in both the second and third UIWebView. However, it does nothing and when I look at the console output, it prints the char c infinitely.

Sorry for the lengthy question, I will appreciate any help!


Are you sure this is only the delegate of the first UIWebView?

Whatever you do, include some more verbose logging. I.e.

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

and also

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

to find the cause of the loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜