0

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

3
  • 1
    What is subView here? Is it a UIView? Commented Feb 17, 2014 at 8:49
  • oh sorry// subView is UIwebview. Commented Feb 17, 2014 at 8:50
  • and I'm already try in -(void)webViewDidFinishLoad:(UIWebView *)webView T-T Commented Feb 17, 2014 at 9:03

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

shouldStartLoadWithRequest calls before any content loaded, so you need to add some check that is not first request, or move all code to for example webViewDidFinishLoad
Thanks,and I'm already try in -(void)webViewDidFinishLoad:(UIWebView *)webView T-T but Thanks
you are welcome, please also update question, or start another one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.