Thursday, January 17, 2013

Javascript to Obj-c Injection (iphone)

To control in UIwebview  via javascript  Injection

Here we are overriding method so that we can launch  this on separate browser rather than opening in webview .

- (void)webViewDidFinishLoad:(UIWebView *)myWebView {
    [self.webView stringByEvaluatingJavaScriptFromString:@"var script = document.createElement('script');"
     "script.type = 'text/javascript';"
     "script.text = \"var ; (url ,name)  { var prefix='ns://'; "
     "open_(prefix+url);return (prefix+url)"
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

 And then handle the special case in

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
    if ([[[inRequest URL] scheme] isEqualToString:@"ns"] == YES)
        [self.webView stopLoading];
               NSLog(@"it works do what ever you want ");


No comments: