I’m trying to write an Eclipse plugin that displays some information as an HTML page. For this I want to use SWT Browser widget. The problem is that when I set browser’s content via setText, nth-child selectors do not work, but when I set the exact same content via setUrl("file://..., they work correctly. Why the rendering is different and how can I achieve the same rendering with setText as with setUrl?
I’m creating the Browser with SWT.NONE, since I do not want to force users to install Safari or Firefox.
This is the HTML where the problem is reproducible:
<!doctype html><html><head>
<style type="text/css">
div:nth-child(2n) { background-color: #f00; }
</style>
</head><body>
<div>1</div>
<div>2</div>
<div>3</div>
</body></html>
Having used the browser’s
setText()method extensively, I’ve not seen any behavior like what you’re describing.Is it possible that this is a local intranet quirks-mode / compatibility mode issue? IE defaults its rendering engine differently based on the source of the content – and, by default, it behaves differently when rendering intranet content versus internet content (and content on your local filesystem is treated as intranet content.) That’s my recollection anyway, all I remember for sure is that there’s a fair amount of voodoo unless you explicitly set the compatibility header.
Does adding the following meta tag change the behavior?
Also, do you have an appropriate
DOCTYPEdefined in the HTML you’re adding withsetText()?