Some websites use the following trick to detect whether a browser's javascript is enabled:
<html>
<head>
<noscript>
<meta http-equiv='refresh'
content='0;url=NoScript.html'>
</noscript>
</head>
<body onload='document.form.submit()'>
<form name='form' action='HasScript.html'></form>
</body>
</html>
If it is enabled, the <meta> tag inside the <noscript> tag is of course ignored; when it is disabled, the <meta> tag causes a refresh to a different page. In HttpUnit using NekoHtml 0.9.1 this works fine. When NekoHTML 1.9.6 is used, however, the <noscript> tag is moved into the body by the parser, and the <meta> tag does nothing. Certainly it seems odd to have a <noscript> tag in the <head> section, but browsers actually do support this (I have tried Firefox 2.0 and Internet Explorer 6.0 on Windows). Can this behavior be restored?
Logged In: YES
user_id=402164
Originator: NO
I guess that the change is a consequence of a fix for http://sourceforge.net/tracker/index.php?func=detail&aid=1723287&group_id=195122&atid=952178.
In fact different things are incorrect:
- you should surely handle meta refresh in body too as FF does it
- parsing an example like yours results in FF into a <noscript> node placed between </head> and <body>!
- NekoHTML should have a feature to specify if <noscript> content should be parsed or not (in other words if js is activated or not) because a normal browser doesn't start parsing the <noscript> content at all when JS is activated
Logged In: YES
user_id=37920
Originator: YES
Upon further examination, I find that I had misdiagnosed the problem. What is actually happening is that when nekoHTML sees the <noscript> tag, it *ends* the <head> element and starts a new <body> node with no attributes. So, if I modify the example to
<html>
<head>
<noscript>
<meta http-equiv='refresh' content='0;url=NoScript.html'>
</noscript>
<title>something</title>
</head>
<body onload='document.form.submit()'>
<form name='form' action='HasScript.html'></form>
</body>
</html>
nekoHTML changes this to:
<html>
<head>
</head>
<body>
<noscript>
<meta http-equiv='refresh' content='0;url=NoScript.html'>
</noscript>
<title>something</title>
<form name='form' action='HasScript.html'></form>
</body>
</html>
which is clearly wrong.
https://github.com/HtmlUnit/htmlunit-neko is a far more advanced version of this parser.
But also in the latest versions of this project is a feature named 'http://cyberneko.org/html/features/parse-noscript-content' that can be used to switch on the behavior you expect.