问题
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