1

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');
    }
}

What I cannot accomplish is such a simple task:

var myfunc = new myFunc();
myfunc.info();

in the UIWebView. How can I instantiate a new object and call a function of that object by using:

[webViewObject stringByEvaluatingJavaScriptFromString:@"myfunc.info();"];

I'm struggling about this.

1 Answer 1

0

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();"];
}
Sign up to request clarification or add additional context in comments.

Comments

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.