admin管理员组文章数量:1355540
I'm trying to follow the very short, simple setup instructions at under section "Creating a browser-like BOM/DOM/Window". Unfortunately, after the 3rd line (the .createWindow step), I do console.log(window) and it prints an empty object. There should be at least window.document there, but there isn't. It seems as though document.createWindow is acting the same as jsdom.createWindow.
Here's my code so far:
var jsdom = require('jsdom').jsdom;
document = jsdom("<html><head></head><body>hello world</body></html>");
window = document.createWindow();
console.log(window); // output: {}
console.log(window.document.innerHTML); // error, cannot read innerHTML on undefined
So, what stupid thing am I doing wrong?
FYI document is created correctly. Printing it outputs a very large object.
I am using a Mac.
I'm trying to follow the very short, simple setup instructions at https://github./tmpvar/jsdom under section "Creating a browser-like BOM/DOM/Window". Unfortunately, after the 3rd line (the .createWindow step), I do console.log(window) and it prints an empty object. There should be at least window.document there, but there isn't. It seems as though document.createWindow is acting the same as jsdom.createWindow.
Here's my code so far:
var jsdom = require('jsdom').jsdom;
document = jsdom("<html><head></head><body>hello world</body></html>");
window = document.createWindow();
console.log(window); // output: {}
console.log(window.document.innerHTML); // error, cannot read innerHTML on undefined
So, what stupid thing am I doing wrong?
FYI document is created correctly. Printing it outputs a very large object.
I am using a Mac.
Share Improve this question edited Jul 2, 2012 at 21:25 Anonymous asked Jul 2, 2012 at 21:02 AnonymousAnonymous 3,4143 gold badges38 silver badges52 bronze badges 2- this works for me and not sure why are you getting those errors. – Kishore Commented Jul 2, 2012 at 21:17
- Node.js version and jsdom version? – Ryan Olds Commented Jul 3, 2012 at 16:08
2 Answers
Reset to default 5var jsdom = require('jsdom').jsdom;
document = jsdom('<!doctype html><html><body>hello jsdom</body></html>');
window = document.createWindow();
console.log(window);
var txt = window.document.body.innerHTML;
console.log(txt);
Problem was due to an installation error with Contextify. I'm used to developing on either Windows or *NIX and on Mac, due to *NIX terminal, assumed I would have things like Make. Problem was solved by installing Xcode with mand line tools, which installs Make among other things, which solved installation error for Contexify, which resolved the overall issue.
本文标签: javascriptjsdom documentcreateWindow() returns empty for nonempty documentStack Overflow
版权声明:本文标题:javascript - jsdom document.createWindow() returns empty for non-empty document - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744025955a2578042.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论