generalize fixLinks to handle #anchors

master
https://www.google.com/accounts/o8/id?id=AItOawmK9HFqQh4HBRfrRONxYE22cglDFTfFbaw 2011-07-13 02:03:51 -04:00 committed by admin
parent 7828f97fdd
commit 032823e452
1 changed files with 25 additions and 1 deletions

View File

@ -36,4 +36,28 @@ This can be placed in `page.tmpl`:
...
</html>
This script has not been extensively tested.
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;
}
}