Small Javascript trick

Think your comic can improve? Whether it's art or writing, composition or colouring, feel free to ask here! Critique and commentary welcome.

Post Reply
User avatar
Joel Fagin
nothos adrisor (GTC)
Posts: 6014
Joined: Mon Mar 29, 2004 1:15 am
Location: City of Lights
Contact:

Small Javascript trick

Post 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
Image

User avatar
Fiore42
Regular Poster
Posts: 75
Joined: Mon Oct 25, 2004 7:51 am
Location: Japan
Contact:

Post 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.
Image

User avatar
Joel Fagin
nothos adrisor (GTC)
Posts: 6014
Joined: Mon Mar 29, 2004 1:15 am
Location: City of Lights
Contact:

Post 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
Image

User avatar
Joel Fagin
nothos adrisor (GTC)
Posts: 6014
Joined: Mon Mar 29, 2004 1:15 am
Location: City of Lights
Contact:

Post 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
Image

User avatar
Joel Fagin
nothos adrisor (GTC)
Posts: 6014
Joined: Mon Mar 29, 2004 1:15 am
Location: City of Lights
Contact:

Post 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
Last edited by Joel Fagin on Thu Jan 27, 2005 8:52 pm, edited 1 time in total.
Image

User avatar
Carlin
...or Crossfire
Posts: 1560
Joined: Sun May 23, 2004 9:13 pm
Location: Paragon City

Post by Carlin »

That's spiffy! I'll have to give it a try when I'm working on a website.
I am The Poster Formerly Known as Crossfire. Or PFKAC. ...has a certain ring to it, no?

Post Reply