-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.js
More file actions
32 lines (24 loc) · 798 Bytes
/
example.js
File metadata and controls
32 lines (24 loc) · 798 Bytes
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
const FORM = document.querySelector('#the-form');
const HIDDEN_FIELD_SNAPSHOT = FORM.querySelector('input.screenshot');
// Just for example purposes.
const RESULT = document.querySelector('.result .inner-content');
FORM.addEventListener('submit', function (e) {
const form = this;
// Stop submit event.
e.preventDefault();
// Create the snapshot.
const promise = html2canvas(form);
// We have the snapshot ready.
promise.then(function (canvas) {
// Set the server snapshot id.
HIDDEN_FIELD_SNAPSHOT.value = canvas.toDataURL();
// Just for example purposes.
let img = new Image();
img.src = canvas.toDataURL();
RESULT.innerHTML = '';
RESULT.appendChild(img);
// Send the form to the server.
//form.submit();
}
);
});