在viewDidLoad中调用UIWebView的stringByEvaluatingJavaScriptFromString是否正确? [英] Is it correct to invoke stringByEvaluatingJavaScriptFromString of UIWebView in viewDidLoad?
本文介绍了在viewDidLoad中调用UIWebView的stringByEvaluatingJavaScriptFromString是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在iOS 5.0中,此代码正确工作:
- (void)viewDidLoad
{
[super viewDidLoad];
[webView stringByEvaluatingJavaScriptFromString:@document.body.style.backgroundColor = \#41414C \;];
}
但是在iOS 4.2中没有背景发生。
如何在html没有加载的时候设置web View的背景?
解决方案
在我的情况我使用webview:webViewDidFinishLoad方法来评估JavaScript。它在4.2中正常工作,但由于我没有在iOS 5中测试过它,我不确定它在该版本中的工作情况。
I need to set the background of webView at a time when the html has not loaded.
In iOS 5.0 this code is correctly working:
- (void)viewDidLoad
{
[super viewDidLoad];
[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.backgroundColor=\"#41414C\";"];
}
But in iOS 4.2 nothing happening with background.
How can I set background of web View at a time when the html has not loaded?
解决方案
In my case I used webview:webViewDidFinishLoad method to evaluate javascript. It was working correctly in 4.2 but since I haven't tested it in iOS 5, I am not sure about its working in that version.
这篇关于在viewDidLoad中调用UIWebView的stringByEvaluatingJavaScriptFromString是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文