-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
37 lines (32 loc) · 1.03 KB
/
script.js
File metadata and controls
37 lines (32 loc) · 1.03 KB
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
let isVisual = true;
function toggleView() {
const editor = document.getElementById('editor');
const htmlView = document.getElementById('htmlView');
if (isVisual) {
htmlView.value = editor.innerHTML.trim();
editor.style.display = 'none';
htmlView.style.display = 'block';
} else {
editor.innerHTML = htmlView.value.trim();
htmlView.style.display = 'none';
editor.style.display = 'block';
}
isVisual = !isVisual;
}
function copyHTML() {
const htmlView = document.getElementById('htmlView');
const editor = document.getElementById('editor');
let textToCopy = '';
if (isVisual) {
textToCopy = editor.innerHTML.trim();
} else {
textToCopy = htmlView.value.trim();
}
const tempInput = document.createElement('textarea');
tempInput.value = textToCopy;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);
alert('HTML copied to clipboard!');
}