diff options
author | https://www.google.com/accounts/o8/id?id=AItOawmK9HFqQh4HBRfrRONxYE22cglDFTfFbaw <John@web> | 2011-07-13 02:03:51 -0400 |
---|---|---|
committer | admin <admin@branchable.com> | 2011-07-13 02:03:51 -0400 |
commit | 032823e45267b6ecf2b83ce39438b3dcad73cb67 (patch) | |
tree | 566c4f9e2a84282a0686f1170a554bf59920f43b /doc | |
parent | 7828f97fddc49d2e8968825edc26de3e107e91af (diff) | |
download | ikiwiki-032823e45267b6ecf2b83ce39438b3dcad73cb67.tar ikiwiki-032823e45267b6ecf2b83ce39438b3dcad73cb67.tar.gz |
generalize fixLinks to handle #anchors
Diffstat (limited to 'doc')
-rw-r--r-- | doc/tips/JavaScript_to_add_index.html_to_file:_links.mdwn | 26 |
1 files changed, 25 insertions, 1 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 index a11c807e8..250bb26af 100644 --- a/doc/tips/JavaScript_to_add_index.html_to_file:_links.mdwn +++ b/doc/tips/JavaScript_to_add_index.html_to_file:_links.mdwn @@ -36,4 +36,28 @@ This can be placed in `page.tmpl`: ... </html> -This script has not been extensively tested.
\ No newline at end of file +This script has not been extensively tested. + +--- + +A version that handles anchors: + + + function fixLinks() { + var scheme = location.protocol; + if (scheme != "file:") return; + var links = document.getElementsByTagName("a"); + for (var i = links.length; --i >= 0; ) { + var link = links[i]; + var href = link.href; + var anchor = ""; + var anchorIndex = href.indexOf("#"); + if (anchorIndex != -1) { + anchor = href.substring(anchorIndex); + href = href.substring(0, anchorIndex); + }; + var hlen = href.length; + if (hlen > 0 && link.protocol==scheme && href.charAt(hlen-1) == "/") + links[i].href = href + "index.html" + anchor; + } + } |