-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
55 lines (51 loc) · 2.01 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head>
<title>How to Capture Screenshot of Page using JavaScript</title>
<link rel='stylesheet' href='form.css' type='text/css' />
</head>
<body>
<div class="phppot-container">
<h1>How to Capture Screenshot of Page using JavaScript</h1>
<p>
<button id="capture-screenshot">Capture Screenshot</button>
</p>
</div>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript"
src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<script type="text/javascript">
$('#capture-screenshot').click(function() {
const screenshotTarget = document.body;
html2canvas(screenshotTarget).then(canvas => {
// to image as png use below line
// const base64image = canvas.toDataURL("image/png");
// show the image in window use below line
// window.location.href = base64image;
// screenshot appended to the body as canvas
document.body.appendChild(canvas);
dataURL = canvas.toDataURL();
// to print the screenshot in console use below line
// console.log(dataURL);
// following line is optional and it is to save the screenshot
// on the server side. It initiates an ajax call
pushScreenshotToServer(dataURL);
});
});
function pushScreenshotToServer(dataURL) {
$.ajax({
url: "push-screenshot.php",
type: "POST",
data: {
image: dataURL
},
dataType: "html",
success: function() {
console.log('Screenshot pushed to server.');
}
});
}
</script>
</body>
</html>