问题
I am trying to use jsdom to analyze some html content. Examples that i have seen use the .createWindow() method of a jsdom.jsdom document based on html content.
But when I try to follow these examples, my document does not have a .createWindow() method.
var getaPage=function (req, res, callback) {
jsdom.defaultDocumentFeatures={
FetchExternalResources : ['script'],
ProcessExternalResources : ['script'],
MutationEvents : '2.0',
QuerySelector : false
};
var htmlDoc = '<html lang="en-US">' +
'</html>';
var tstDocument=jsdom.jsdom(htmlDoc);
for (var attr in tstDocument){
if (attr == 'createWindow') {
console.log('Found it');
}else{
console.log('not it');
};
};
};
When I run this, I get a bunch of 'not it' and no 'Found it'.
Why do I not have a .createWindow() method?
回答1:
jsdom's API changed quite a bit with the 1.0 release. The createWindow()
method is from the old API. You should be able to get the document's window just by accessing tstDocument.defaultView
, just like you'd do if you were in a browser.
来源:https://stackoverflow.com/questions/26492552/jsdom-jsdom-missing-a-createwindow-method