Kabitis
Kabitis

Reputation: 51

UIWebView javascript with IOS Issue

I try to use IOS call function from javascript but still not working Help me pleasee!!

this javascript

function geturl(getdata) {
   // document.getElementById('test1').src = '';
     alert(getdata);
}

and IOS code

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {

    NSURL *URL = [inRequest URL];
    NSString *stringURL = [NSString stringWithFormat:@"%@",URL];
    NSString *urlString = inRequest.URL.absoluteString;

    NSString * getdata  = @"come please";
    NSString * sendBack = [NSString stringWithFormat:@"geturl('%@')",getdata];
    [subView stringByEvaluatingJavaScriptFromString:sendBack];// subView is UIWebview

  return YES;
}

I try to use like this but data is not alert I don't know what happen help me please!!


  -(void)webViewDidFinishLoad:(UIWebView *)webView{

        if (loadingPage < [book count]) {

            NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[book objectAtIndex:loadingPage] ofType:@"html" inDirectory:@""]];
            [[scrollView.subviews objectAtIndex:loadingPage] loadRequest:[NSURLRequest requestWithURL:url]];
            [[scrollView.subviews objectAtIndex:loadingPage] setHidden:NO];
            loadingPage++;
            subView.scrollView.bounces = NO;
            [[subView scrollView] setBounces: NO];       
        }
        NSString * getdata  = @"come please";
        NSString * sendBack = [NSString stringWithFormat:@"geturl('%@')",getdata];
        [subView stringByEvaluatingJavaScriptFromString:sendBack];


    }

I also try this one but still not working. If I got something wrong please tell me

Upvotes: 0

Views: 673

Answers (1)

sage444
sage444

Reputation: 5684

please ensure subView is UIWebView object, and also you steel need return YES or NO in shouldStartLoadWithRequest method. And one more little solution - open safari debugger with simulator or device and check this function manually in console

Upvotes: 1

Related Questions