在PhantomJS腳本文件,我試圖加載定義陣列的本地JavaScript文件:包括JS與PhantomJS
var webPage = require('webpage'),
page = webPage.create();
injected = page.injectJs('./codes.js');
if (injected) {
console.log('injected codes.js');
console.log(myCodes);
}
phantom.exit();
codes.js:
myCodes = new Array();
myCodes[0] = { "stuff": "here" };
// more like this
我會希望myCodes數組可用。 然而,我收到
injected codes.js
ReferenceError: Can't find variable: myCodes