Phantomjs-includejs-method
提供:Dev Guides
PhantomJS-includeJS()
*includeJs* メソッドは、ページで外部JSファイルを実行し、完了時にコールバック関数を実行します。
構文
その構文は次のとおりです-
var wpage = require('webpage').create();
wpage.includeJs(jsfile,function(){});
例
次の例は、* includeJs()*メソッドの使用を示しています。
var wpage = require('webpage').create();
wpage.onConsoleMessage = function (str) {
console.log('CONSOLE: ' + msg);
}
wpage.open('http://localhost/tasks/al', function(status) {
wpage.includeJs('http://localhost/tasks/testscript.js', function() {
var foo = wpage.evaluate(function() {
return testcode();
});
console.log(foo);
});
});
testscript.js
function testcode () {
return "welcome to phantomjs";
}
上記のプログラムは、次の output を生成します。
welcome to phantomjs