-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathtest-attribute-value.html
More file actions
45 lines (44 loc) · 1.4 KB
/
test-attribute-value.html
File metadata and controls
45 lines (44 loc) · 1.4 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
<!doctype html>
<html>
<head>
<title>Attribute Nodes Shenanigans</title>
<script>
this.onnload = function () {
var div = document.querySelector('div');
// grab first attribute
var attribute = div.attributes[0];
// trap attribute name and value
var name = attribute.name;
var value = attribute.value;
// remove the attribute
div.removeAttribute(name);
if (attribute.name !== name) alert('Attribute name compromised');
// cry here if you are using Edge
if (attribute.value !== value) alert('Attribute value compromised');
// see the emptiness as value if you are using Edge
div.appendChild(
document.createTextNode(
[attribute.name, attribute.value].join(': ')
)
);
// do the same with the body
div = document.body;
attribute = document.body.attributes[0];
name = attribute.name;
value = attribute.value;
div.removeAttribute('align');
if (attribute.name !== name) alert('Body attribute name compromised');
// cry louder since it does NOT happen this time
if (attribute.value !== value) alert('Body attribute value compromised');
div.appendChild(
document.createTextNode(
[attribute.name, attribute.value].join(': ')
)
);
};
</script>
</head>
<body align="right">
<div align="right"></div>
</body>
</html>