当我将鼠标悬停在网页的图片上时,它会在状态栏javascript:main.somefunction("arg1","arg2","arg3")
中显示JavaScript功能。是否有可能在网页上下文中运行该功能并使用PhantomJS呈现结果?我可以在PhantomJS中运行网页的JavaScript功能吗?
2
A
回答
0
如果你有一个元素如
<a href='javascript:main.somefunction("arg1","arg2","arg3")'>
<img src='someImage.jpg'>
</a>
,那么你应该看到在状态栏中的链接的URI。由于页面必须知道main
对象才能调用该对象,因此main
必须是全局范围内的对象(在window
对象上)。您可以在页面上下文中拨打main.somefunction("arg1","arg2","arg3")
或window.main.somefunction("arg1","arg2","arg3")
。
如果函数异步更改页面,则必须等待更改。静态延迟可以用setTimeout()
完成。如果您需要等待特定条件,则可以使用waitFor()
function from the examples directory。
page.open(url, function(status){
if (status === "fail") {
console.log("Load failed");
phantom.exit(1);
return;
}
page.evaluate(function(){
main.somefunction("arg1","arg2","arg3")
});
setTimeout(function(){
page.render("screenshot.png");
phantom.exit();
}, 3000); // 3 seconds delay
});
+1
现在我得到一个错误TypeError:undefined不是一个函数(评估'main.somefunction(“arg1”,“arg2”,“arg3”)') – user5704481
相关问题
- 1. 可以在webkit浏览器的Android网页上运行Javascript功能吗?
- 2. 我可以在JavaScript中运行JavaScript吗?
- 3. 我可以配置Phantomjs在Firefox中运行在Internet Explorer吗?
- 4. 我可以检索在间隔中运行的功能吗?
- 5. 我可以在PhantomJS之外运行Durandal的测试框架吗?
- 6. 我可以使用Node.js中的所有Javascript功能/功能吗
- 7. 我可以在运行时更改Button或TextView的功能吗?
- 8. 我可以调用正在运行的Windows服务功能吗?
- 9. 我的功能未在JavaScript中运行
- 10. Firebug可以运行我的网站吗?
- 11. 是否可以使用网站的网址在网站上运行javascript功能?
- 12. 我可以在整个页面加载之前运行JavaScript吗?
- 13. 我们可以在webview中加载基本的javascript功能吗?
- 14. 如何在网页中运行外部JavaScript功能?
- 15. 我可以运行多个javascript onload吗?
- 16. Indy可以运行Javascript吗?
- 17. 我可以在iPhone上运行JavaScript运行时(如v8)吗?
- 18. 我可以在JQueryTemplate中运行一行JavaScript吗?
- 19. MS Project 2013 + ASP.Net + Sharepoint 2013 - 我可以运行网页部分吗?
- 20. 我们可以在网页以外使用Javascript吗?
- 21. 在android中我可以在运行时更改操作栏窗口功能吗?
- 22. 我可以在Java中运行PHP吗?
- 23. 我可以在Heroku中运行coffeescript吗?
- 24. 我可以在功能中调用功能吗?
- 25. 我可以在运行时处理我的布局页面吗?
- 26. 运行在网页上的Javascript可以连接到远程服务器吗?
- 27. 我可以在HTML文档中运行Nodejs JavaScript脚本吗?
- 28. 我可以在(加载的)页面上运行自己的JavaScript吗?
- 29. JavaScript可以读取网页吗?
- 30. 我可以在网页上嵌套JavaScript脚本吗?
您使用哪个PhantomJS版本?请注册onConsoleMessage,onError,onResourceError,onResourceTimeout事件([Example](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf#file-1_phantomerrors-js))。也许有错误。 –