Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7817711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:19:27+00:00 2026-06-02T06:19:27+00:00

I am new to nodejs. I want to use jsdom to parse some web

  • 0

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.

my 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);
  }
});

and the html page here

<html>
<head>
    <script>
    var a = 0;
    function loads(){
        a=1000;
    }
    </script>
</head>
<body onload='loads()'>
</body>
</html>

and got error message below

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)

It reports the loads function was not defined, but it actually was declared in the web page.

Can anyone give some suggestions, or just simply tell me jsdom cannot process the scripts embedded in page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:19:28+00:00Added an answer on June 2, 2026 at 6:19 am

    Here’s the code that you want to have:

    var fs = require('fs');
    var jsdom = require('jsdom');
    var doc   = jsdom.jsdom(fs.readFileSync("a.html"), null, {
              features: {
                FetchExternalResources   : ['script'],
                ProcessExternalResources : ['script'],
                MutationEvents           : '2.0',
            }
        });
    
    var window = doc.createWindow();
    jsdom.jQueryify(window, "http://code.jquery.com/jquery-1.5.min.js", function() {
        console.log(window.a);
        console.log(window.$().jquery); //jquery version
    });
    

    Your code will not work because the jsdom.env method does not process scripts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to NodeJS. Yes I know I could use a framework, but I want
i use seam framework to develop a web site. I want to share one
I am building one web application, nodejs is my webserver. I want to send
I want to write some javascript classes which inherit from the DOM Node interface...
I am new to NodeJS and Socket IO, I use PHP and jQuery. I
I use the following code to display xml as a treeview. Now I want
Hi I want to read an XML document but it may have some of
I am new to nodejs but I did get something to work last night
I'm using Nodejs and Socket.io. When the client connects, new JavaScript objects are created.
Suppose I have a list, in which no new nodes are added or deleted.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.