Note that there are some explanatory texts on larger screens.

plurals
  1. POjsdom doesn't process script inside web page
    text
    copied!<p>I am new to nodejs. I want to use jsdom to parse some web pages which may contain script code inside. But I got error said the function or variable was not defined. Can anyone give some directions about this.</p> <p>my code</p> <pre><code>var jsdom = require('jsdom'); jsdom.env({ html: 'http://10.200.0.10:8080/test/a.html', scripts: [ 'http://code.jquery.com/jquery-1.5.min.js' ], done: function(errors, window) { var $ = window.$; window.onload(); console.log(window.a); } }); </code></pre> <p>and the html page here</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script&gt; var a = 0; function loads(){ a=1000; } &lt;/script&gt; &lt;/head&gt; &lt;body onload='loads()'&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and got error message below</p> <pre><code>dfddddfdf undefined:1: ReferenceError: loads is not defined loads() ^ ReferenceError: loads is not defined at unknown source at /root/node_modules/jsdom/node_modules/contextify/lib/contextify.js:10:24 at /root/node_modules/jsdom/lib/jsdom/level1/core.js:1024:50 at /root/testnode.js:18:12 at Array.0 (/root/node_modules/jsdom/lib/jsdom.js:199:39) at EventEmitter._tickCallback (node.js:192:40) node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ ReferenceError: loads is not defined at unknown source at /root/node_modules/jsdom/node_modules/contextify/lib/contextify.js:10:24 at /root/node_modules/jsdom/lib/jsdom/level1/core.js:1024:50 at /root/testnode.js:18:12 at Array.0 (/root/node_modules/jsdom/lib/jsdom.js:199:39) at EventEmitter._tickCallback (node.js:192:40) </code></pre> <p>It reports the loads function was not defined, but it actually was declared in the web page.</p> <p>Can anyone give some suggestions, or just simply tell me jsdom cannot process the scripts embedded in page.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload