
- 文件系统模块
- 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('http://localhost/tasks/a.html', 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"; }
以上程序会生成以下 输出。
welcome to phantomjs
phantomjs_webpage_module_methods.htm
广告