Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何截图网页的特定部分_Javascript_Php_Html - Fatal编程技术网

Javascript 如何截图网页的特定部分

Javascript 如何截图网页的特定部分,javascript,php,html,Javascript,Php,Html,我使用下面的脚本截图的网页,我成功地获得了整个网页作为截图,但我只想捕获网页的特定部分,所以你可以建议我什么是改变要做的代码 <script type="text/javascript" src="js/html2canvas.js"></script> and function canvas(){ html2canvas(document.body, { onrendered: function(canva

我使用下面的脚本截图的网页,我成功地获得了整个网页作为截图,但我只想捕获网页的特定部分,所以你可以建议我什么是改变要做的代码

      <script type="text/javascript" src="js/html2canvas.js"></script>  and 

       function canvas(){
        html2canvas(document.body, {
        onrendered: function(canvas) {
       document.body.appendChild(canvas);
       },
      width: 1200,
     height:700
    })};
和
函数画布(){
html2canvas(document.body{
onrendered:函数(画布){
document.body.appendChild(画布);
},
宽度:1200,
身高:700
})};

更改
html2canvas
的第一个参数,以指向要复制的DOM元素

现在您将它指向
,因此
document.body

您可以通过键入以下内容来选择具有特定
id
div

html2canvas(document.getElementById( "the_id_of_the_element" ), {...}...
所以你给它的第一个参数,就是它要关注的元素。 如果还使用jQuery,则可以执行以下操作:

html2canvas( $('.class_of_element'), {...}...
文件: