summaryrefslogtreecommitdiff
path: root/doc/tips
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-09-10 04:32:55 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-09-10 04:32:55 +0000
commit4a1132c49fad62f3bbe895df112e16c9d0b0a41c (patch)
tree72839a01986f23494ca68a53e8682b535b253e9b /doc/tips
parentace91c7d0b849c0922e05680eb2c85d11ba2d061 (diff)
web commit by http://per.bothner.myopenid.com/: JavaScript tip to enable browsing using file: URLS
Diffstat (limited to 'doc/tips')
-rw-r--r--doc/tips/JavaScript_to_add_index.html_to_file:_links.mdwn39
1 files changed, 39 insertions, 0 deletions
diff --git a/doc/tips/JavaScript_to_add_index.html_to_file:_links.mdwn b/doc/tips/JavaScript_to_add_index.html_to_file:_links.mdwn
new file mode 100644
index 000000000..a11c807e8
--- /dev/null
+++ b/doc/tips/JavaScript_to_add_index.html_to_file:_links.mdwn
@@ -0,0 +1,39 @@
+The source file `foo/bar.mdwn` or `foo/bar.html` generates the
+page `foo/bar/index.html`, but the links to the page appear
+as "`foo/bar/`". This is fine (and recommended) for pages
+served by an http server, but it doesn't work when browsing
+the pages directly using `file:` URL. The latter might be
+desirable when testing pages before upload, or if you want to
+read pages when off-line without access to a web server.
+
+Here is a JavaScript "`onload`" script which fixes the URLs
+if the `local.protocol` isn't `http` or `https`:
+
+ function fixLinks() {
+ var scheme = location.protocol;
+ if (scheme=="http:" || scheme=="https:") return;
+ var links = document.getElementsByTagName("a");
+ for (var i = links.length; --i >= 0; ) {
+ var link = links[i];
+ var href = link.href;
+ var hlen = href.length;
+ if (hlen > 0 && link.protocol==scheme && href.charAt(hlen-1) == "/")
+ links[i].href = href + "index.html";
+ }
+ }
+
+This can be placed in `page.tmpl`:
+
+ <html>
+ <head>
+ <script language="JavaScript">
+ function fixLinks() {
+ ...
+ }
+ </script>
+ </head>
+ <body onload="javascript:fixLinks();">
+ ...
+ </html>
+
+This script has not been extensively tested. \ No newline at end of file