/[suikacvs]/webroot/www/url/urlresolution.en.html
Suika

Contents of /webroot/www/url/urlresolution.en.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download) (as text)
Sat Jul 5 14:36:58 2008 UTC (16 years, 4 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +18 -1 lines
File MIME type: text/html
Show effective base URL

1 wakaba 1.1 <!DOCTYPE HTML>
2     <html lang=en>
3     <head>
4     <title>Live URL Resolution Viewer</title>
5     <link rel=author href="http://suika.fam.cx/~wakaba/who?" title=Wakaba lang=ja>
6     <style>
7     h1 {
8     font-size: 100%;
9     }
10     textarea {
11     width: 90%;
12     height: 3em;
13     }
14     iframe {
15     visibility: hidden;
16     width: 0;
17     height: 0;
18     }
19     var {
20     color: orange;
21     }
22     </style>
23     <script>
24     document.createElement ('output');
25    
26     var updateTimer = 0;
27     function update () {
28     if (updateTimer) {
29     clearTimeout (updateTimer);
30     }
31     updateTimer = setTimeout (realUpdate, 100);
32     } // update
33    
34     function htescape (s) {
35     return s.replace (/&/g, '&amp;')
36     .replace (/</g, '&lt;')
37     .replace (/>/g, '&gt;')
38     .replace (/"/g, '&quot;');
39     } // htescape
40    
41     function htescape2 (s) {
42     return s.replace (/&/g, '&amp;')
43     .replace (/</g, '&lt;')
44     .replace (/>/g, '&gt;')
45     .replace (/"/g, '&quot;')
46     .replace (/[\u0000-\u0020\u007F-\u00A0]/g, function (t) {
47     return '<var>&amp;#x' + t.charCodeAt (0).toString (16).toUpperCase () + ';</var>';
48     });
49     } // htescape2
50    
51     function realUpdate () {
52     var baseURL = document.getElementById ('base-url').value;
53     var resolvedURL = document.getElementById ('resolved-url').value;
54    
55     var pl = document.getElementById ('permalink');
56     pl.href = location.pathname + '?' + encodeURIComponent (baseURL) + ';' +
57     encodeURIComponent (resolvedURL);
58    
59     var iframe = document.getElementsByTagName ('iframe')[0];
60     var doc = iframe.contentWindow.document;
61     doc.open ();
62     doc.write ('<!DOCTYPE HTML>');
63     doc.write ('<base href="' + htescape (baseURL) + '">');
64     doc.write ('<a href="' + htescape (resolvedURL) + '">xx</a>');
65     doc.close ();
66    
67 wakaba 1.3 var aEl = doc.getElementsByTagName ('a')[0];
68     var resultURL = aEl.href;
69 wakaba 1.1 var output = document.getElementsByTagName ('output')[0];
70     output.innerHTML = '';
71     if (typeof (resultURL) == 'undefined') {
72 wakaba 1.2 output.innerHTML = '(<code>undefined</code>)';
73 wakaba 1.1 } else if (resultURL === null) {
74 wakaba 1.2 output.innerHTML = '(<code>null</code>)';
75 wakaba 1.1 } else if (resultURL === '') {
76     output.innerHTML = '(empty string - URL resolution failed?)';
77     } else {
78     output.innerHTML = '<code>' + htescape2 ('' + resultURL) +
79     '</code> of type <code>' + htescape (typeof (resultURL)) + '</code>';
80     }
81 wakaba 1.3
82     var resultBaseURL = aEl.baseURI;
83     var output = document.getElementById ('output-base-url');
84     output.innerHTML = '';
85     if (typeof (resultBaseURL) == 'undefined') {
86     output.innerHTML = '(<code>undefined</code>)';
87     } else if (resultBaseURL === null) {
88     output.innerHTML = '(<code>null</code>)';
89     } else if (resultBaseURL === '') {
90     output.innerHTML = '(empty string)';
91     } else {
92     output.innerHTML = '<code>' + htescape2 ('' + resultBaseURL) +
93     '</code> of type <code>' + htescape (typeof (resultBaseURL)) + '</code>';
94     }
95 wakaba 1.1 } // realUpdate
96    
97     window.onload = function () {
98     if (location.search) {
99     var q = location.search.substring (1).split (/;/);
100     if (q[0] != null) {
101     document.getElementById ('base-url').value = decodeURIComponent (q[0]);
102     }
103     if (q[1] != null) {
104     document.getElementById ('resolved-url').value = decodeURIComponent (q[1]);
105     }
106     }
107    
108     update ();
109     }; // window.onload
110     </script>
111     </head>
112     <body>
113     <h1>Live URL Resolution Viewer
114     (<a rel=bookmark id=permalink href>Permalink</a>)</h1>
115    
116     <dl>
117     <dt><label for=resolved-url>Resolved URL</label>:
118 wakaba 1.2 <dd><textarea id=resolved-url oninput="update()" onchange="update()" onkeypress="update()"></textarea>
119 wakaba 1.1 <dt><label for=base-url>Base URL</label>:
120 wakaba 1.2 <dd><textarea id=base-url oninput="update()" onchange="update()" onkeypress="update()"></textarea>
121 wakaba 1.1 </dl>
122     <hr>
123     <dl>
124 wakaba 1.2 <dt>Result (Using <code>base href</code> and
125     <code>HTMLAnchorElement.href</code>):
126 wakaba 1.1 <dd><output></output>
127 wakaba 1.3 <dt>Effective base URL (as per <code>Node.baseURI</code>)
128     <dd><output id=output-base-url></output>
129 wakaba 1.1 </dl>
130    
131     <iframe></iframe>
132    
133     </body>
134     </html>

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24