-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtitle_extraction.html
36 lines (32 loc) · 942 Bytes
/
title_extraction.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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title> This is a
BAD title, this < that.</title>
<style type="text/css">
.output {
width: 90%;
}
</style>
<script type="text/javascript">
function copy_val(){
var title = (document.getElementsByTagName('title'))[0];
document.getElementById('output_raw').value = title.innerHTML;
document.getElementById('output_nice').value = (title.textContent || title.innerText).replace(/\s+/g, ' ').replace(/^[ ]*([^ ].*[^ ])[ ]*$/, '$1');
}
</script>
</head>
<body>
<h1>JavaScript and bad titles!</h1>
<input type=button onclick="copy_val();" value="Show Page Title" />
<dl>
<dt>Title inner HTML</dt>
<dd><input type=text class=output
id="output_raw" value="(Click button)" disabled /></dd>
<dt>Title as a browser sees it</dt>
<dd><input type=text class=output
id="output_nice" value="(Click button)" disabled /></dd>
</dl>
</body>
</html>