Reputation: 1886
How can I inject custom CSS into a WebView like changing the background-color:
of http://www.apple.com/. Javascript would also be nice because in the future I would like to have control of the javascript.
Upvotes: 1
Views: 2060
Reputation: 5569
The best way would be the one delineated by Rob Keniger, with this answer: https://stackoverflow.com/a/2475623/307881. This technique should also work for javascript. If it doesn't work off the bat try modifying the DOM after the WebView has finished loading (see below)
You can also directly evaluate a javascript string without accessing the DOM.
First, get your javascript string, then, when your WebView finishes loading its content, use the delegate method of WebFrameLoadDelegate
:
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
[sender stringByEvaluatingJavaScriptFromString:jsStringToInject];
}
Upvotes: 2