-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
70 lines (69 loc) · 2.36 KB
/
index.html
File metadata and controls
70 lines (69 loc) · 2.36 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>HTML Viewer</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
display: flex;
gap: 20px;
}
textarea,
iframe {
flex: 1;
height: 400px;
overflow: auto;
border: 1px solid #ccc;
padding: 10px;
box-sizing: border-box;
resize: none;
}
iframe {
padding: 0;
}
</style>
</head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-NTSZYP8Y9S"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-NTSZYP8Y9S');
</script>
<body>
<h3>HTML Viewer</h3>
<button onclick="render()">Render</button>
<button onclick="download()">Download</button>
<div class="container">
<textarea id="htmlInput" wrap="off" placeholder="Paste HTML here"></textarea>
<iframe id="preview" sandbox="allow-scripts"></iframe>
</div>
<script>
let htmlContent = "";
function render() {
htmlContent = document.getElementById("htmlInput").value.trim();
if (!htmlContent) return;
const iframe = document.getElementById("preview");
iframe.srcdoc = htmlContent;
}
function download() {
htmlContent = document.getElementById("htmlInput").value.trim();
if (!htmlContent) return;
const parser = new DOMParser();
const doc = parser.parseFromString(htmlContent, "text/html");
const title = doc.querySelector("title")?.textContent.trim() || "untitled";
const blob = new Blob([htmlContent], { type: "text/html" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `${title}.html`;
a.click();
URL.revokeObjectURL(url);
}
</script>
</body>
</html>