-
Notifications
You must be signed in to change notification settings - Fork 6
/
gbcr_table.html
62 lines (53 loc) · 2.08 KB
/
gbcr_table.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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Range getBoundingClientRect in table test</title>
<script type="text/javascript">
function rectToString(rect) {
if (rect) {
return "(" + rect.left + ", " + rect.top + "), (" + rect.right + ", " + rect.bottom + ")";
} else {
return "No rect";
}
}
window.onload = function() {
var log = document.getElementById("log");
log.value = "";
var tds = document.getElementsByTagName("td"), td1 = tds[0], td2 = tds[1];
var td1Text = td1.firstChild;
function logRect(name, range) {
log.value += name + ": " + rectToString(range.getClientRects()[0]) + "\n";
}
log.value += "TD rect: " + rectToString(td1.getBoundingClientRect()) + "\n";
var range = document.createRange();
range.setStart(td1, 0);
range.collapse(true);
logRect("collapsed at offset 0 in TD", range);
range.setStart(td1, 1);
range.collapse(true);
logRect("collapsed at offset 1 in TD", range);
range.setStart(td1, 2);
range.collapse(true);
logRect("collapsed at offset 2 in TD", range);
range.setStart(td1Text, 0);
range.collapse(true);
logRect("collapsed at TD text char 0", range);
range.setStart(td1Text, 1);
range.collapse(true);
logRect("collapsed at TD text char 1", range);
var p = document.getElementsByTagName("p")[0];
range.setStart(p, 1);
range.collapse(true);
logRect("collapsed at offset 1 in P", range);
};
</script>
</head>
<body>
<p>A para</p>
<textarea id="log" rows="10" cols="80"></textarea>
<table border="1">
<tr><td>One <b>two</b></td></tr>
<tr><td>Three</td></tr>
</table>
</body>
</html>