我有一个UIWebView,它在初始化后从缓存加载HTML-file:
UIWebView *tempWebView = [[UIWebView alloc] init];
tempWebView.delegate = self;
[self.view addSubview:tempWebView];
[tempWebView loadHTMLString:htmlString baseURL:baseURLString];而不是在webViewDidFinishLoad:(UIWebView *)webView中,我尝试执行javascript
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[[webView stringByEvaluatingJavaScriptFromString:jsString] floatValue];
// other manipulations...
[webView removeFromSuperview];
}问题是HTML-code具有外部依赖关系,例如:
<link rel="stylesheet" href="css/book.css" type="text/css"/>有这样一种印象,这个*.css没有时间加载,所以javascript-code返回了一个错误的值。如果延迟执行webViewDidFinishLoad:(UIWebView *)webView的内容(假设2.0f秒),一切都会好的。
但这种延迟在不同的设备和情况下可能会有所不同。那么,我如何确定已经加载了所有依赖项来执行我的javascript-code?
发布于 2012-07-19 19:31:46
在中使用此代码
webViewDidStartLoad
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[[webView stringByEvaluatingJavaScriptFromString:jsString] floatValue];
// other manipulations...
}https://stackoverflow.com/questions/11559733
复制相似问题