以编程方式从 javascript 调用 Firefox 扩展
我见过这个优秀的 Firefox 扩展,Screengrab!。它拍摄网页的“图片”并将其复制到剪贴板或保存到 png 文件。我需要这样做,但是使用一个新的网页,来自我在 javascript 中的 url。我可以在新窗口中打开网页,但随后我必须调用扩展(而不是按下控件)并在页面完全加载后保存页面。
是否可以?
I have seen this excellent firefox extension, Screengrab!. It takes a "picture" of the web page and copies it to the clipboard or saves it to a png file. I need to do so, but with a new web page, from an url I have in javascript. I can open the web page in a new window, but then I have to call the extension -not to press the control- and saves the page once the page is fully loaded.
Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我非常确定无法通过网页内容访问任何 Firefox 插件。这可能会在 Firefox 浏览器中产生隐私和/或安全问题(因为用户从未授予您在其计算机上访问此类内容的权限)。出于这个原因,我相信 Firefox 附加组件在完全不同的 JavaScript 上下文中运行,从而使这完全不可能。
但是,正如 Dmitriy 的回答所述,可以执行服务器端解决方法。
I am pretty certain that it is not possible to access any Firefox add-on through web page content. This could create privacy and/or security issues within the Firefox browser (as the user has never given you permission to access such content on their machine). For this reason, I believe Firefox add-ons run in an entirely different JavaScript context, thereby making this entirely impossible.
However, as Dmitriy's answer states, there are server-side workarounds that can be performed.
ScreenGrab 看起来没有任何 javascript API。
有一个 PHP 解决方案用于将网页保存为图像。
如果您需要从 JavaScript(从客户端)执行此操作 - 您可以:
第 1 步:创建一个 PHP 服务器应用程序来执行此操作(请参阅链接),并接受 JSONP 调用。
第 2 步: 创建一个客户端页面 (JavaScript),用于向该 PHP 脚本发送 JSONP 请求。请参阅我的回答,这将帮助您创建这样的要求。
Does not look like ScreenGrab has any javascript API.
There is a PHP solution for Saving Web Page as Image.
If you need to do it from JavaScript (from client side) - you can:
Step 1: Create a PHP server app that does the trick (see the link), and that accepts JSONP call.
Step 2: Create a client side page (JavaScript) that will send a JSONP request to that PHP script. See my answer here, that will help you to create such request.