2
在這個腳本中,HTML文檔的body的onLoad屬性中定義的函數不會被jsdom調用。爲什麼不?爲什麼jsdom不會處理腳本?
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);
感謝tmpvar。雖然沒有解決這個問題:( – Trindaz 2012-03-31 00:53:29
任何jsdom特定的調試技巧? – Trindaz 2012-03-31 00:54:24