为什么jsdom不会处理脚本?

时间:2012-03-30 07:15:54

标签: node.js jsdom

在此脚本中,jsdom不会调用HTML文档正文的onLoad属性中定义的函数。为什么不呢?

var testHTML = '<html> \n' +
'    <head> \n' +
'        <title>AJAX Testing</title> \n' +
'        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script> \n' +
'        <script type="text/javascript"> \n' +
'            function loaded(){ \n' +
'                $("body").html("<p>AJAX was used to update the contents of this page!</p>"); \n' +
'            } \n' +
'        </script> \n' +
'    </head> \n' +
'    <body onLoad="loaded()"> \n' +
'        <p>No ajax work has been done</p> \n' +
'    </body> \n' +
'</html>';
var jsdom = require('jsdom');
var options = {
        features:{
          FetchExternalResources:['script']
        , ProcessExternalResources:['script']
        }
    }
var document = jsdom.jsdom(testHTML, null, options)
var window = document.createWindow();
console.log(window.document.innerHTML);

1 个答案:

答案 0 :(得分:0)

尝试使用<body onload="loaded()">