Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of LTjake (4001)

Thursday March 20, 2003
12:39 PM

base + named hrefs

[ #11131 ]

Well, since my journal is already a bitch fest... :)

I've been constructing a site. I decided to use the <base href="..."> to _try_ simplify things in my documents. This is fine and dandy, except for named hrefs (i.e. links to items like #top).

When using base, named hrefs will only point to named refs on the base page. I decided to try and solve things with javascript. Here's what i came up with:

code.js:

function namedRef(strLink, strText) {
    var intPosition = document.location.href.indexOf("#");

    if (intPosition < 0) {
        intPosition = document.location.href.length;
    }

    return "<a href=\"" + document.location.href.substring(0, intPosition) + "#" + strLink + "\">" + strText + "<" + "/a>";
}


somewhere in the html file:

<script type="text/javascript">
document.write(namedRef('top', 'Top'));
</script>

This is great! It'll give me things like test.html#top and if you've already clicked on a named href, it won't duplicate it. It even works in Netscape 4. It bungholios things for lynx though.

...There's one tine exception to things working in Netscape 4. It won't do links that end in a slash (that may not be the EXACT condition, but for what i know, it works on site/index.html but not site/)

Perhaps i should forget using the base tag. It seems like it's more trouble than it's worth.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.