可以“截图”一下吗?使用 Canvas 的页面?
我有一个页面,我们使用 CSS 定位一堆元素,并使用 JS 更改它们的“顶部和左侧”位置。
我收到报告称这些事情已经错位,但用户有动机对此撒谎以“作弊”,所以我不确定他们是否说的是实话。我正在想办法找出他们是否在说谎,并找到一些“证据”。
我知道 Canvas 有一种方法可以从图像元素或另一个画布元素复制图像信息(类似于 BitBlt 操作)。
是否有可能以某种方式,使用 Canvas(或使用其他东西,Flash,等等),拍摄页面的一部分的“图片”?
再说一次,我并不是试图从 获取信息。我试图复制用户看到的内容,它由几个绝对定位的 HTML 元素组成(我最关心这些位置),并以某种方式将其上传到服务器。
我知道这是不可能的,但也许我错过了一些东西。
有什么想法吗?
I have a page where we're positioning a bunch of elements using CSS, and changing their "top and left" positions using JS.
I've had reports that these things have been misaligned, but a user has the motive to lie about this to "cheat", so I'm not exactly sure whether they're telling the truth. I'm trying to find a way to figure out whether they're lying or not, and to have some "proof".
I know that Canvas has a method to copy image information from an image element, or another canvas element (kind of a BitBlt operation).
Would it be possible to somehow, with Canvas (or with something else, Flash, whatever), take a "picture" of a piece of the page?
Again, I'm not trying to take information from an <image>
. I'm trying to copy what the user sees, which is comprised of several HTML elements positioned absolutely (and I care most about those positions) and somehow upload that to the server.
I understand this can't be done, but maybe I'm missing something.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
之前有人问过一个和这个有点相似的问题。滚动到 Youtube 底部并单击“报告错误”链接。 Google 的反馈工具(Javascript 驱动)基本上执行您所描述的操作。从我查看的代码来看,它使用画布并有一个基于 JavaScript 的 JPEG 编码器,可以构建 JPG 图像并发送给 Google。
这肯定需要大量工作,但我相信您可以完成类似的事情。
Somebody asked a question earlier that's somewhat similar to this. Scroll to the bottom of Youtube and click the "Report a Bug" link. Google's Feedback Tool (Javascript driven), essentially does what you described. Judging by what I looked at of its code, it uses canvas and has a JavaScript-based JPEG encoder which builds a JPG image to send off to Google.
It would definitely be a lot of work, but I'm sure you could accomplish something similar.
如果可以选择商业解决方案,请查看 SnapEngage。
单击右上角的“帮助”按钮即可查看其实际情况。这是一个屏幕截图:-
设置非常简单,您只需复制并粘贴几行即可JavaScript 代码。
SnapEngage 使用 Java Applet 来截取屏幕截图,此处 是一篇关于其工作原理的博客文章。
If a commercial solution is an option, Check out SnapEngage.
Click on the "help" button in top-right to see it in action. Here is a screenshot:-
Setup is pretty straight-forward you just have to copy and paste a few lines of javascript code.
SnapEngage uses a Java Applet to take screenshots, Here is a blog post about how it works.
是的,你可以看下面的演示
在下面的代码中,我在 body 标记内定义了表格,但是当您运行此代码时,它将显示图像快照。
html2canvas 官方文档:- http://html2canvas.hertzen.com/
要下载 html2canvas.js 库,您可以使用另外,如果您无法从官方链接找到:-
https://github.com/niklasvh/html2canvas/downloads
[我不对此链接负责:P :P :P]
Yes you can See following demo
In below code I have define table inside body tag but when you run this code then it will display image snapshot.
html2canvas official Documentation:- http://html2canvas.hertzen.com/
To download html2canvas.js library you can use also if you unable to find from official link :-
https://github.com/niklasvh/html2canvas/downloads
[I am not responsible for this link :P :P :P]
您可以使用 元素,目前仅支持火狐。
这里
#mysite
是其内容用作背景的元素在 Firefox 中打开: http://jsfiddle.net/qu2kz/3/
(在 FF 27 上测试)
You can use the element, that currently is only supported by Firefox.
Here
#mysite
is the element whose content is used as backgroundOpen in Firefox: http://jsfiddle.net/qu2kz/3/
(tested on FF 27)
我不认为你能做到这一点。但是,您可以递归地获取
clientHeight
,clientWidth
,offsetTop
和offsetLeft
确定页面上所有元素的位置并将其发送回服务器。I don't think that you can do that. However, you could recursively fetch
clientHeight
,clientWidth
,offsetTop
andoffsetLeft
to determine the positions of all elements on the page and send it back to the server.在 Firefox 上,您可以创建一个使用 canvas.drawWindow 将 Web 内容绘制到画布上的插件。 https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas#Rendering_Web_Content_Into_A_Canvas
我认为目前有一种方法可以在 WebKit 上做到这一点。
On Firefox, you can create an AddOn that uses canvas.drawWindow to draw web content to a canvas. https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas#Rendering_Web_Content_Into_A_Canvas
I don't think there's a way to do that on WebKit at the moment.
这是可以做到的,但有一些限制。有一些技巧,这些正是许多扩展程序进行屏幕截图的方法。从您的描述来看,您似乎并不是在寻找要部署的通用客户端解决方案,而只是在寻找用户或某些用户可以使用和提交的东西,所以我想使用扩展程序就可以了。
Chrome:
我可以向您推荐我的开源 Chrome 扩展程序 Blipshot,它的作用正是如此:
https://github.com/folletto/Blipshot
只是提供一些背景知识:
Firefox:
从 1.5 版开始,您可以在 Firefox 中构建使用自定义画布扩展
drawWindow
的扩展,该扩展比chrome.tabs.captureVisibleTab
更强大代码>相当于Chrome。一些信息在这里:https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas
It can be done, with some limitations. There are some techniques, and these are exactly how many extensions do screenshots. From your description it seems that you aren't looking for a generic, client side solution to be deployed, but just something that a user or some users could use and submit, so I guess using an extension would be fine.
Chrome:
I can point you to my opensource Chrome extension, Blipshot, that does exactly that:
https://github.com/folletto/Blipshot
Just to give some background:
chrome.tabs.captureVisibleTab
and require access to the tabs from the manifest.Firefox:
In Firefox since 1.5 you can build extensions that use a custom extension of canvas,
drawWindow
, that is more powerful than thechrome.tabs.captureVisibleTab
equivalent of Chrome. Some informations are here:https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas