- 檔案系統模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 系統模組
- PhantomJS - 屬性
- Web 伺服器模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 其他
- 命令列介面
- PhantomJS - 截圖
- PhantomJS - 頁面自動化
- PhantomJS - 網路監視
- PhantomJS - 測試
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用資源
- PhantomJS - 快速指南
- PhantomJS - 有用資源
- PhantomJS - 討論
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('https:///tasks/a.html', function(status) {
wpage.includeJs('https:///tasks/testscript.js', function() {
var foo = wpage.evaluate(function() {
return testcode();
});
console.log(foo);
});
});
testscript.js
function testcode () {
return "welcome to phantomjs";
}
以上程式會生成以下 輸出。
welcome to phantomjs
phantomjs_webpage_module_methods.htm
廣告