- 文件系统模块
- PhantomJS - 属性
- PhantomJS - 方法
- 系统模块
- PhantomJS - 属性
- Web 服务器模块
- PhantomJS - 属性
- PhantomJS - 方法
- 杂项
- 命令行界面
- PhantomJS - 屏幕截图
- PhantomJS - 页面自动化
- PhantomJS - 网络监控
- PhantomJS - 测试
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 实用资源
- PhantomJS - 快速指南
- PhantomJS - 实用资源
- PhantomJS - 讨论
PhantomJS - injectJs()
injectJs 方法从指定文件向页面注入外部脚本。如果文件不在当前目录中,则它将使用 libraryPath 进一步搜索该文件。如果文件已注入,则返回 true,否则返回 false。
语法
其语法如下 −
wpage.injectJs(filename);
示例
以下示例展示如何使用 injectJs() 方法。
var wpage = require('webpage').create();
wpage.open('https:///tasks/a.html', function(status) {
if (wpage.injectJs('tscript1.js')) {
var msg = wpage.evaluate(function() {
return testcode();
});
console.log(msg);
phantom.exit();
}
});
tscript1.js
function testcode () {
return "welcome to phantomjs";
}
以上程序生成以下输出。
welcome to phantomjs
phantomjs_webpage_module_methods.htm
Advertisement