WebView load css on the fly
objective-c, webkit, webview
Solution
You should access the DOM using the Objective-C DOM API and insert the appropriate `<link>` or `<style>` element into the DOM.
DOMDocument* domDocument=[webView mainFrameDocument];
DOMElement* styleElement=[domDocument createElement:@"style"];
[styleElement setAttribute:@"type" value:@"text/css"];
DOMText* cssText=[domDocument createTextNode:@"body{font-weight:bold;}"];
[styleElement appendChild:cssText];
DOMElement* headElement=(DOMElement*)[[domDocument getElementsByTagName:@"head"] item:0];
[headElement appendChild:styleElement];
Problem
I have the following code which loads and html file into a webview ``` - (void)awakeFromNib{ NSString *resourcesPath = [[NSBundle mainBundle] resourcePath]; NSString *htmlPath = [resourcesPath stringByAppendingString:@"/main.html"]; [[self mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]]; } ``` How would i dynamically load a css file (in the most efficient manner) as it does not suit to have the css file link in the html file