本文介绍了UIWebView +自定义JavaScript对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function myFunc() ){
var myVar;
函数信息(){
alert('info');
}
}
我无法完成的是这样一个简单的任务: / p>
var myfunc = new myFunc();
myfunc.info();
在UIWebView中。我怎么能实例化一个新的对象,并通过使用以下对象来调用该对象的函数:
[webViewObject stringByEvaluatingJavaScriptFromString:@myfunc.info ();];
我正在为此付出努力。 解决方案
刚解决。足以在您使用它的viewcontroller中实现协议,然后声明:
webView.delegate = self;
以及:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSLog(@webViewDidFinishLoad);
[webView stringByEvaluatingJavaScriptFromString:@var obj = new myObject();];
稍后:
- (void)myAwesomeAction
{
[webView stringByEvaluatingJavaScriptFromString:@obj.func();];
}
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.
解决方案
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();"];
}
这篇关于UIWebView +自定义JavaScript对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!