Skip to content Skip to sidebar Skip to footer

Uiwebview + Custom Javascript Object

I'm using a UIWebView with local jquery and a script that defines a function, like this: function myFunc() { var myVar; function info() { alert('info'); } } W

Solution 1:

Just solved. Is sufficient to implement the protocol in the viewcontroller you are using it, then declare:

webView.delegate = self;

and in:

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSLog(@"webViewDidFinishLoad");
    [webView stringByEvaluatingJavaScriptFromString:@"var obj = new myObject();"];
}

later:

-(void)myAwesomeAction
{
    [webView stringByEvaluatingJavaScriptFromString:@"obj.func();"];
}

Post a Comment for "Uiwebview + Custom Javascript Object"