zoukankan      html  css  js  c++  java
  • 通过按钮截取当前网页成png或jpeg格式的图片并保存

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script type="text/javascript" src="jquery-1.7.2.min.js"/>
    <script type="text/javascript" src="html2canvas.js"/>
    </head>
    <body>
    <a id="down_load_hidden" target="blank" style="display: none;"></a>

    <a id="down_button" href="javascript:void(0)" onclick="domShot('qqCont')">保存当前页</a>
    <div id="qqCont" class="qqCont">
    需要截图的样式
    </div>
      
    <script>
    /**
    * 调用html2canvas框架进行截图下载功能
    * @param domId 容器Id
    * author Levin
    */
    function domShot(domId) {
    //0.5.0-beta4方法
    html2canvas(document.querySelector("#" + domId), {
    allowTaint: true,
    height: $("#" + domId).outerHeight() + 20
    }).then(function (canvas) {
    var timestamp = Date.parse(new Date());
    $('#down_button').attr('href', canvas.toDataURL());
    $('#down_button').attr('download', timestamp + '.png');
    var fileObj = document.getElementById("down_load_hidden");
    fileObj.click();
    });
    }
    </script>
    //一般情况html2canvas.js中的截取部分不支持取全部截取 所以要将页面所有部分截取得 修改html2canvas.js中的一下部分
    //未修改前
    <script>
    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;
    });
    </script>
    //修改后
    <script>
    //添加自定设置宽度高度
    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;
    });
    </script>


    </body>
    </html>
  • 相关阅读:
    ◆ C++中通过溢出覆盖虚函数指针列表执行代码
    关于在OnTimer中连续弹出对话框的讨论
    SetTimer
    Windows内核对象
    日志收缩
    暴力求值
    低级问题
    函数限制
    字符串找字段和表
    android错误提示说明汇总
  • 原文地址:https://www.cnblogs.com/johnny-cli/p/8004512.html
Copyright © 2011-2022 走看看