|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Dynamically adding new <script> element.Hi,
There's unexpected result when I tried to add new <script> element. Here's a code snippet: page.executeJavaScript("var script = document.createElement('script')"); page.executeJavaScript("script.setAttribute('type', 'text/javascript')"); page.executeJavaScript("script.text = 'var execSpec = 42;'"); page.executeJavaScript("document.head.appendChild(script);"); page.executeJavaScript("document.head.removeChild(script);"); System.out.println(page.executeJavaScript("window.execSpec").getJavaScriptResult()); The result should be '42', but it returns 'undefined'. It works fine on web browsers. Actually, this is a part of Mootools library code, "core/Browser.js": function $exec(text){ if (!text) return text; if (window.execScript){ window.execScript(text); } else { var script = document.createElement('script'); script.setAttribute('type', 'text/javascript'); script.text = text; document.head.appendChild(script); document.head.removeChild(script); } return text; }; I'm working on HtmlUnit 2.1. Is it fixed? I cannot try this on head version. Head is fail to package because of failed test. Regards, Sung-Ahn Kim. |
|
|
|
|
|
Re: Dynamically adding new <script> element.As Ahmed said, please try HEAD. If you're having trouble with the unit tests, you can skip the tests via Maven (-DskipTests with the latest versions). See the Maven docs for more info.
On Sat, Jun 28, 2008 at 10:31 AM, ccoroom <ccoroom@...> wrote:
-- Daniel Gredler http://daniel.gredler.net/ ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Htmlunit-user mailing list Htmlunit-user@... https://lists.sourceforge.net/lists/listinfo/htmlunit-user |
|
|
Re: Dynamically adding new <script> element.Sorry, Ahmed.
I missed important portion of the mootools library code. They define 'document.head' but the htmlunit cannot recognize it. And, unfortunately it doesn't work on htmlunit with FF2 configuration. (It works fine on IE configuration) Oh, I'm working on htmlunit 2.1 and 2.2-snapshot. Here's my code: ---- <head> <script type="text/javascript" src="../Source/Core/Core.js"></script> <script type="text/javascript" src="../Source/Core/Browser.js"></script> <script type="text/javascript"> function test() { $exec.call($exec, 'var execSpec = 42'); alert(execSpec); } </script> </head> <body> <input id=myId type=button onclick='test()' value='Test'> </body> </html> ---- You can see the mootools code from the repository (Core.js, Browser.js): http://github.com/mootools/mootools-core/tree/master/Source/Core I know to see the external link is quite bothering you. Sorry, but its content somewhat large to paste. Regards, Sung-Ahn Kim.
|
|
|
|
|
|
|
| Free Forum Powered by Nabble | Forum Help |