I have an anchor tag with a local href value and a JavaScript function that uses the href value, but directs it to a slightly different place than usual. Tag looks like
<a onclick="return follow(this);" href="sec/IF00.html"></a>
and a JavaScript function that looks like
baseURL = 'http://www.someotherdomain.com/'; function follow(item) { location.href = baseURL + item.href; }
I would expect that item.href would just return a short string of "sec / IF00.html", but instead it returns the full href, "http://www.thecurrentdomain.com/sec/IF00.html". Is there a way that I can pull out just the short href as put in the anchor <a> tag? Or do I lose that by natural HTML behavior?
I suppose I could use a string manipulation to do this, but it gets tricky because my local page may actually be "http://www.thecurrentdomain.com/somedir/somepath/sec/IF00.html", and my href field may or may not have a subdirectory in it (for ex href="page.html" vs. href="sub/page.html" ), so I cannot always just remove every thing before the last slash.
You may wonder why I'm asking about this, and that is because it will just make the page a lot cleaner. If it is not possible to get only a short href (as indicated in the anchor <a> ), then I could probably just insert an extra field in the tag, for example link="sec/IF00.html" , but again, that would be a bit dirtier.
javascript html href
Michael Plautz Mar 15 '13 at 18:39 2013-03-15 18:39
source share