Hi,
Both options still work in the current version. The key is both are applied very early during the page's life cycle, thus they are very likely to be overriden by styles loaded later in the page. For example, you can use the following code to turn a page's default background color to red:
Code: C#
EO.WebEngine.BrowserOptions options = new EO.WebEngine.BrowserOptions();
options.UserStyleSheet = "body { background-color: red; }";
webView.SetOptions(options);
However these style options are applied
before the actual page contents are loaded. So if you have the following HTML in your page:
Code: HTML/ASPX
<style>
body
{
background-color:green;
}
</style>
<body>
Am I red?
</body>
Then the text will not be
red because the style in the page has overriden this to be green.
The same principle applies when you use JSInitCode to create style element because it is created
before the actual page content is loaded.
To resolve this issue you must change
when the style is applied. One way to do this is to still use JSInitCode but instead of creating the style element right away, you can delay it until the page has been loaded. For example:
Code: C#
string js = @"
window.addEventListener('load', function()
{
var style = document.createElement('style');
style.textContent = 'body { background-color: red; }';
document.body.appendChild(style);
});";
webView.JSInitCode = js;
This will still run JSInitCode before the page has been loaded. However the code does not create the style element right away. It instead delay the creation until window.onload event. At that point the page contents has already been loaded and now you are free to override whatever styles set by the page, instead of being overriden by it.
Hope this helps. Please feel free to let us know if you still have any questions.
Thanks!