Is it correct to invoke stringByEvaluatingJavaScriptFromString of UIWebView in viewDidLoad?

北慕城南 提交于 2019-12-23 19:43:07

问题


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?


回答1:


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.




回答2:


  • hide the webview until it is not loaded and set a view behind it with your desired background-color.
  • when your webview is loaded, show it and set the background color of the html inside the webview


来源:https://stackoverflow.com/questions/8678932/is-it-correct-to-invoke-stringbyevaluatingjavascriptfromstring-of-uiwebview-in-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!