Page 1 of 1

Small Javascript trick

Posted: Thu Jan 27, 2005 5:23 pm
by Joel Fagin
My site is up and being played with and I just threw together a minor little Javascript trick that's a help. You know that every link or image URL in a Keenspace page has to have the "/" on the front? That means that unless you have your website stored in the root directory of you harddrive, all the links will be broken when you're working on your pages and templates at home.

This'll make the pages work on both Keenspace and your harddrive all the time. It goes in the HEAD section of your webpage.

Code: Select all

<script type="text/javascript">
<!--
  if (!(document.URL).match("indextemplate"))
    document.write("<BASE HREF='http://yoursitehere.keenspace.com/'>");
//-->
</script>

<NOSCRIPT><BASE HREF='http://yoursitehere.keenspace.com/'></NOSCRIPT>
Unfortunatly, it has to be the whole "http://yoursitehere.keenspace.com/" rather than just "/" or else IE gets messed up.

- Joel Fagin

Posted: Thu Jan 27, 2005 5:33 pm
by Fiore42
Oh, whoa... I'm going to go give this a try. Thanks! I've been getting kind of tired of all the "broken links", god wot.

Posted: Thu Jan 27, 2005 6:03 pm
by Joel Fagin
Minor addendum: It'll work for people who have Javascript turned off, but you do need to have Javascript turned on when working on the pages at home.

Not that many people leave JS off, mind, but worth mentioning.

- Joel Fagin

Posted: Thu Jan 27, 2005 6:55 pm
by Joel Fagin
Bah. Doesn't always work and I don't know why.

Well, I know one reason why, but there's at least one other.

- Joel Fagin, Gun Jumper

Posted: Thu Jan 27, 2005 7:14 pm
by Joel Fagin

Code: Select all

<script type="text/javascript"><!--
    if (document.domain == "yoursitehere.keenspace.com")
      document.write("<BASE HREF='http://yoursitehere.keenspace.com/'>");
//--></script>

<NOSCRIPT><BASE HREF='http://yoursitehere.keenspace.com/'></NOSCRIPT>
Better, but not guarenteed. I mean, I think it works, but I'm all paranoid now.

- Joel Fagin

Posted: Thu Jan 27, 2005 8:19 pm
by Carlin
That's spiffy! I'll have to give it a try when I'm working on a website.