Forum How do I...?

Unable to access Javascript variables of other Javascript files

mastahfull
For some reason we are unable to access JS variables from JS files in other JS files when running Prince.
We are able to use the local variables of the JS file and access the DOM.
mikeday
Do you have an example?
mastahfull
Sure.

Given I have 2 .js files included in script tags on the HTML page. If I have "var a = 0;" in file1.js and try to do the following in file2.js: "$('#someDiv').append(a);" in the DOM the a is undefined.

When I just do the following in file3.js: "var b = 0; $('#someDiv').append(b);" The dom does show 0 in the #someDiv.

This is also true for functions and anything else in JS files.
mikeday
Could there be an exception thrown that is blocking one of the scripts? Please try the attached example which works fine.
  1. script1.js0.0 kB
  2. script2.js0.0 kB
  3. test.html0.1 kB
mastahfull
Heyhey, sorry for the late response.

It actually was an exception blocking the scripts :).