Ron*_*Ron 4 javascript node.js jsdom
我一直在搞 jsdom ,我不知道如何从 html 页面运行函数。例如,我有一个像这样的简单页面:
<html>
<body>
Hello
</body>
<script>
function test() {
document.write("Bye bye")
}
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
我想test从 jsdom执行该函数。我该怎么做?我试过简单地调用该函数,但节点抱怨它不存在。
jsdom.env({
url : "http://localhost:8000/test.html",
features : {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script']
},
done : function (error, window) {
test(); // I'd like to do something like this.
console.log(window.document.innerHTML);
}
});
Run Code Online (Sandbox Code Playgroud)
显然,正确的方法是使用window.test(),以及适当的功能:
jsdom.env({
url : "http://localhost:8000/test.html",
features : {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script']
},
done : function (error, window) {
window.test();
console.log(window.document.innerHTML);
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5444 次 |
| 最近记录: |