我有一个 ASP.Net 应用程序,作为所需的功能,用户希望能够截屏。虽然我知道这可以模拟,但如果有一种方法可以获取 URL(或当前呈现的页面)并将其转换为可以存储在服务器上的图像,那就太好了。
这是疯了吗?有没有办法做到这一点?如果有,有参考吗?
我有一个 ASP.Net 应用程序,作为所需的功能,用户希望能够截屏。虽然我知道这可以模拟,但如果有一种方法可以获取 URL(或当前呈现的页面)并将其转换为可以存储在服务器上的图像,那就太好了。
这是疯了吗?有没有办法做到这一点?如果有,有参考吗?
我现在可以告诉你,在浏览器内部没有办法做到这一点,也不应该有. 想象一下,您的页面在 iframe 中嵌入了 GMail。然后,您可以窃取此人的 GMail 收件箱的屏幕截图!
这可以通过让浏览器“屏蔽”所有违反跨域限制的 iframe 和嵌入来确保安全。
您当然可以编写一个扩展来执行此操作,但请注意上述安全注意事项。
更新:您可以使用画布实用程序函数来获取与您的代码同源的页面的屏幕截图。甚至还有一个库可以让你这样做:http ://experiments.hertzen.com/jsfeedback/
你可以在这里找到其他可能的答案:Using HTML5/Canvas/JavaScript to take screenshots
Browsershots有一个 XML-RPC 接口和可用的源代码(在 Python 中)。
我使用了免费的程序集 UrlScreenshot.dll,您可以在此处下载。
效果很好!
还有WebSiteScreenShot但它不是免费的。
您可以尝试一个浏览器插件,例如IE7 Pro for Internet Explorer,它允许您将当前站点的屏幕截图保存到磁盘上的文件中。我敢肯定那里也有类似的 FireFox 插件。
如果你想做你描述的事情。您需要调用一个打印 IE 输出的外部进程,如此处所述。
你为什么不采取另一种方法?
If you have the need that users can view the same content over again, then it sounds like that is a business requirement for your application, and so you should be building it into your application.
Structure the URL so that when the same user (assuming you have sessions and the application shows different things to different users) visits the same URL, they always see same thing. They can then bookmark the URL locally, or you can even have an application feature that saves it in a user profile.
Part of this would mean making "clean urls", eg, site.com/view/whatever-information-needed-here.
If you are doing time-based data, where it changes as it gets older, there are probably a couple possible approaches.