-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
56 lines (42 loc) · 1.69 KB
/
index.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
56
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://files.codepedia.info/files/uploads/iScripts/html2canvas.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<main id="html-content-holder">
<h1>Screen Capture Application Using Screen Capture Api</h1>
<button id="btn-Preview-Image" onclick="show()" class="btn btn_blue">Take ScreenShot</button>
<a id="btn-Convert-Html2Image" class="btn btn_red" href="#" style="text-decoration: none;">Download as image</a>
</main>
<h3>Preview :</h3>
<div id="previewImage" class="view">
</div>
<script>
one = document.getElementById("btn-Preview-Image");
function show() {
document.getElementById("btn-Convert-Html2Image").style.display = "block";
document.getElementById("btn-Convert-Html2Image").style.width = "130px";
}
$(document).ready(function(){
var element = $("#html-content-holder"); // global variable
var getCanvas; // global variable
$("#btn-Preview-Image").on('click', function () {
html2canvas(element, {
onrendered: function (canvas) {
$("#previewImage").append(canvas);
getCanvas = canvas;
}
});
});
$("#btn-Convert-Html2Image").on('click', function () {
var imgageData = getCanvas.toDataURL("image/png");
// Now browser starts downloading it instead of just showing it
var newData = imgageData.replace(/^data:image\/png/, "data:application/octet-stream");
$("#btn-Convert-Html2Image").attr("download", "your_pic_name.png").attr("href", newData);
});
});
</script>
</body>
</html>