node.js - jsdom: Run a page's javascript functions -


this question has answer here:

i've been messing around jsdom , can't figure out how run functions html page. example, i've got simple page this:

<html>   <body>     hello   </body>   <script>     function test() {       document.write("bye bye")     }   </script> </html> 

and i'd execute test function jsdom. how go doing this? i've tried calling function, node complains doesn't exist.

jsdom.env({     url : "http://localhost:8000/test.html",     features : {         fetchexternalresources : ['script'],         processexternalresources : ['script']     },     done : function (error, window) {         test(); // i'd this.         console.log(window.document.innerhtml);     } }); 

well apparently correct way window.test(), , appropriate features:

jsdom.env({     url : "http://localhost:8000/test.html",     features : {         fetchexternalresources : ['script'],         processexternalresources : ['script']     },     done : function (error, window) {         window.test();         console.log(window.document.innerhtml);     } }); 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -