-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_sample.html
70 lines (63 loc) · 2.06 KB
/
clean_sample.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Safe Web Page</title>
</head>
<body>
<h1>Safe Web Page Demonstration</h1>
<!-- Safe Display of User Input -->
<div>
<h2>Safe User Input Display</h2>
<form id="safeForm">
<label for="name">Enter your name:</label>
<input type="text" id="name" name="name">
<button type="button" onclick="submitSafeForm()">Submit</button>
</form>
<p id="safeUserInput"></p>
<script>
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
function submitSafeForm() {
var userInput = document.getElementById('name').value;
var safeUserInput = escapeHtml(userInput);
document.getElementById('safeUserInput').innerText = "Hello, " + safeUserInput;
}
</script>
</div>
<!-- Safe URL Display -->
<div>
<h2>Safe URL Display</h2>
<a href="https://www.example.com">Visit Example.com</a>
</div>
<!-- Safe Event Handler -->
<div>
<h2>Safe Event Handler</h2>
<button onclick="safeAlert()">Click me</button>
<script>
function safeAlert() {
alert('This is a safe action!');
}
</script>
</div>
<!-- Safe Image Display -->
<div>
<h2>Safe Image Display</h2>
<img src="valid.jpg" alt="Valid image">
</div>
<!-- Safe SVG Display -->
<div>
<h2>Safe SVG Display</h2>
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</svg>
</div>
</body>
</html>