![](/img/trans.png)
[英]UIWebView stringByEvaluatingJavaScriptFromString not working
[英]loading html the right way to get stringByEvaluatingJavaScriptFromString working
我正在尝试使stringByEvaluatingJavaScriptFromString正常工作。 我确定我将html文件加载错误,只是看不到我做错了。
-(void)viewDidLoad
{
// Load the index.html file as a string from the file system
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString *html = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
// Load/pass it in to webView
[webView loadHTMLString:html baseURL:[[NSBundle mainBundle] bundleURL]];
[super viewDidLoad];
}
我将javascript事件传递/发送到index.html:
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:@"displayName('name');"];
}
我做错了什么?
这是我为此功能编写的代码。
NSString *fullURL = @"url";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
完成加载
-(void)webViewDidFinishLoad:(UIWebView *)webViews {
NSString *testString = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"[ID]\").innerHTML;"];
[webView loadHTMLString:testString baseURL:nil];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.