HTMLIFrameElement.getScreenshot() 编辑

Warning: Removed in Firefox 65.

The getScreenshot() method of the HTMLIFrameElement lets you request a screenshot of a content <iframe>, scaled to fit within a specified maximum width and height. The image will be cropped if necessary but will not be distorted vertically or horizontally.

Note: getScreenshot() waits for the event loop to go idle before it takes the screenshot. It won't wait more than 2000ms (this delay is defined by the Gecko dom.browserElement.maxScreenshotDelayMS preference).

Syntax

var instanceOfDOMRequest =
instanceOfHTMLIframeElement.getScreenshot(maxWidth, maxHeight, mimeType);

Returns

A DOMRequest for handling the screenshot request. Its request.onsuccess handler handles the success case (the screenshot is contained in request.resultas a Blob object), and its request.onerror handler handles the failure case.

Parameters

maxWidth
A number representing the maximum width of the screenshot in device pixels.
maxHeight
A number representing the maximum height of the screenshot in device pixels.
mimeType Optional
A MIME type specifying the format of the image to be returned; if not specified, the default used is image/jpeg. Use image/png to capture the alpha channel of the rendered result by returning a PNG-format image. This lets you get a transparent background for the content <iframe>.

Examples

var browser = document.querySelector('iframe');

var request = browser.getScreenshot(100, 100);

request.onsuccess = function() {
  var blob = request.result;
  var url = URL.createObjectURL(blob);
}

Specification

Not part of any specification.

Browser compatibility

Supported since Firefox 47, in chrome code only. Removed completely in Firefox 65.

Unlikely ever to be supported in other browsers.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:83 次

字数:4085

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文