六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

html5瀏覽器截圖的示例

[摘要]這篇文章主要介紹了html5使用html2canvas實現瀏覽器截圖的示例,非常具有實用價值,需要的朋友可以參考下最近做項目為了解決全局異常信息記錄,研究了一下瀏覽器全屏截圖功能,方便用戶發現異常時能夠快速截圖發給管理員。最終記錄的異常信息如下,上面的【截圖報告管理員】就是使用html2canva...
這篇文章主要介紹了html5使用html2canvas實現瀏覽器截圖的示例,非常具有實用價值,需要的朋友可以參考下

最近做項目為了解決全局異常信息記錄,研究了一下瀏覽器全屏截圖功能,方便用戶發現異常時能夠快速截圖發給管理員。最終記錄的異常信息如下,上面的【截圖報告管理員】就是使用html2canvas前端插件實現的。

html5瀏覽器截圖的示例

html2canvas介紹

以前我們只能通過其他的截圖工具來截取圖像。現代瀏覽器的功能已經越來越強,隨著H5的逐漸普及,瀏覽器本身就可以截圖啦。html2canvas就是這樣一款前端插件,它的原理是將Dom節點在Canvas里邊畫出來。雖然很方便,但有以下限制:

  • 不支持iframe

  • 不支持跨域圖片

  • 不能在瀏覽器插件中使用

  • 部分瀏覽器上不支持SVG圖片

  • 不支持Flash

  • 不支持古代瀏覽器和IE,如果你想確認是否支持某個瀏覽器,可以用它訪問 http://deerface.sinaapp.com/ 試試 :)

由于我的使用場景很簡單,記錄一下異常信息,并且異常頁面也是由自己定義的,那么html2canvas 就足夠使用了。

使用實例

引用jquery,html2canvas即可,使用代碼也很簡單。我這里使用的是 html2canvas 0.5.0 版本


 html2canvas($("#tbl_exception"), {
         onrendered: function (canvas) {
             var url = canvas.toDataURL();
              //以下代碼為下載此圖片功能
             var triggerDownload = $("<a>").attr("href", url).attr("download", getNowFormatDate()+"異常信息.png").appendTo("body");
               triggerDownload[0].click();
               triggerDownload.remove();
           }
   });

第一個參數是要截圖的Dom對象,第二個參數時渲染完成后回調的canvas對象。

NameTypeDefaultDescription
allowTaintbooleanfalseWhether to allow cross-origin images to taint the canvas
backgroundstring#fffCanvas background color, if none is specified in DOM. Set undefined for transparent
heightnumbernullDefine the heigt of the canvas in pixels. If null, renders with full height of the window.
letterRenderingbooleanfalseWhether to render each letter seperately. Necessary ifletter-spacing is used.
loggingbooleanfalseWhether to log events in the console.
proxystringundefinedUrl to the proxy which is to be used for loading cross-origin images. If left empty, cross-origin images won't be loaded.
taintTestbooleantrueWhether to test each image if it taints the canvas before drawing them
timeoutnumber0Timeout for loading images, in milliseconds. Setting it to 0 will result in no timeout.
widthnumbernullDefine the width of the canvas in pixels. If null, renders with full width of the window.
useCORSbooleanfalseWhether to attempt to load cross-origin images as CORS served, before reverting back to proxy

問題分析

介紹完使用之后,說說自己使用中遇到的問題,截圖只能截取當前屏幕內的內容。在查看插件源碼,進行調試之后找到了解決方案。下面貼出源碼和修改后的代碼

源碼:


 return renderDocument(node.ownerDocument, options, node.ownerDocument.defaultView.innerWidth, node.ownerDocument.defaultView.innerHeight, index).then(function(canvas) {
        if (typeof(options.onrendered) === "function") {
            log("options.onrendered is deprecated, html2canvas returns a Promise containing the canvas");
            options.onrendered(canvas);
        }
        return canvas;
    });

修改代碼:


   //2016-02-18修改源碼,解決BUG 對于部分不能截屏不能全屏添加自定義寬高的參數以支持
    var width = options.width != null ? options.width : node.ownerDocument.defaultView.innerWidth;
    var height = options.height != null ? options.height : node.ownerDocument.defaultView.innerHeight;
    return renderDocument(node.ownerDocument, options, width, height, index).then(function (canvas) {
        if (typeof(options.onrendered) === "function") {
            log("options.onrendered is deprecated, html2canvas returns a Promise containing the canvas");
            options.onrendered(canvas);
        }
        return canvas;
    });

主要是讓用戶調用時能夠自定義需要截取Dom對象的寬和高,現在調用方式如下


            $("#btn_screen").on("click", function () {               
                html2canvas($("#tbl_exception"), {
                    height: $("#tbl_exception").outerHeight() + 20,
                    onrendered: function (canvas) {
                        var url = canvas.toDataURL();
                        //以下代碼為下載此圖片功能
                        var triggerDownload = $("<a>").attr("href", url).attr("download", getNowFormatDate()+"異常信息.png").appendTo("body");
                        triggerDownload[0].click();
                        triggerDownload.remove();
                    }
                });
            });

以上就是html5瀏覽器截圖的示例的詳細內容,更多請關注php中文網其它相關文章!


網站建設是一個廣義的術語,涵蓋了許多不同的技能和學科中所使用的生產和維護的網站。




主站蜘蛛池模板: 日本亚欧乱色视频在线观看 | 日韩精品一区二区三区免费视频 | 欧美性大战久久久久久久 | 特a级片 | 天堂√在线中文资源网 | 日韩在线免费看网站 | 五月综合色 | 任我鲁这里有精品视频在线播 | 亚洲综合色在线 | 亚洲精品第四页中文字幕 | 色妹子综合 | 日韩精品免费看 | 日本不卡免费新一二三区 | 日本翁熄系列乱在线视频 | 四虎永久影院永久影库 | 在线视频一区二区三区 | 青青草好吊色 | 亚洲产国偷v产偷v自拍色戒 | 亚洲精品网站日本xxxxxxx | 青青青青手机在线视频观看国产 | 青娱乐在线国产 | 亚洲综合激情丁香六月 | 性网站视频 | 亚洲黄色一区二区 | 欧美在线播放视频 | 在线视频综合网 | 日韩亚射 | 日韩黄色三级 | 中文字幕在线播放第一页 | 色综色天天综合网 | 亚洲国产图片 | 色欲香天天天综合网站 | 午夜高清免费观看视频 | 在线97视频| 亚洲制服在线观看 | 三级国产日产 | 一级黄色a级片 | 性生大片一级毛片免费观看 | 五月情网 | 亚洲波多野结衣日韩在线 | 中文字幕第315页 |