html2canvas:捕获远程网站的截图

时间:2013-05-25 12:16:55

标签: php javascript html2canvas

民间,

我是js的新手,我无法捕获并截取远程网站的屏幕截图。有人能指出我正确的方向

我一直收到这个错误:

未捕获TypeError:对象[object Object]没有方法'html2canvas'index.php:4201 capture index.php:4201 的onclick

我的代码是index.php

<html>
<head>
<title>Hawk-Eye: Have a look at what others are upto</title>
<script type="text/javascript"        src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="http://localhost/Hawk-eye/html2canvas.js"></script>
<script type="text/javascript" src="http://localhost/Hawk-    eye/jquery.plugin.html2canvas.js"></script>
</head>
<body>

<div id="target">
<?php

 $homepage= file_get_contents('http://www.yahoo.com');
 echo $homepage;
?>
</div>

<form method="POST" enctype="multipart/form-data" action="save.php" id="myForm">
<input type="hidden" name="img_val" id="img_val" value="" />
</form>

<script type="text/javascript">

function capture() {
    $('#target').html2canvas({
        onrendered: function (canvas) {
            //Set hidden field's value to image data (base-64 string)
            $('#img_val').val(canvas.toDataURL("image/png"));
            //Submit the form manually
            document.getElementById("myForm").submit();
        }
    });
}

</script>

<input type="submit" value="Take Screenshot" onclick="capture();" />
</body>
</html>

1 个答案:

答案 0 :(得分:0)

下载html4canvas并将其导入为

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