-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
32 lines (29 loc) · 1.12 KB
/
script.js
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
document.querySelector('#print').addEventListener('click', function(event) {
window.print();
});
var inputIds = ['backaddress', 'addressnote', 'address', 'additionalinformation', 'text', 'footer'];
document.querySelector('#share').addEventListener('click', function(event) {
var params = new URLSearchParams();
inputIds.forEach(function(id) {
var text = document.getElementById(id).innerText.trim();
if (text !== '') {
params.set(id, text);
}
});
var url = [document.location.origin, document.location.pathname,
'?', params.toString()].join('');
var shareData = {title: 'Briefvorlage', text: url, url: url};
if ('canShare' in navigator && navigator.canShare(shareData)) {
navigator.share(shareData);
} else {
window.prompt('Kopiere die Vorlage und drücke beliebigen Knopf', url);
}
});
if (document.location.search) {
var params = new URLSearchParams(document.location.search);
inputIds.forEach(function(id) {
if (params.has(id)) {
document.getElementById(id).innerText = params.get(id);
}
});
}