03.22.04

JavaScript The Smart Way

Posted in General at 10 am

As part of importing nearly 400 older entries into GreyMatter, I have had to come up with a work around because of some poor planning and a poor feature set.

GreyMatter (the software that I use to author this journal) has URLs that are made up of serial numbers. If you are looking at a page that has only one entry on it, you’re probably looking at a page with the url of www.bad-seed.org/notes/archives/00000xxx.shtml where the xxx refer to the serial number of the entries. That’s all fine and dandy if you have started counting from 1 and never need to put anything before it, but it sucks if you haven’t thought that far ahead, because you can’t put in entry number 0 or enteries with a negative number.

So when I added my 400 older entries, the URLs for the the original entries now point to 000004xx.shtml, or 000005xx.shtml or 000006xx.shtml or 000007xx.shtml. (I only had 370 some odd ‘new’ entries when I started bringing in the older archives.)

The problem is when I have links to entries that should point to entries that have moved ahead 400 places in the serial numbers. I don’t have control over all of these links: Many of them originate from other people’s weblogs or from search engines or even other informational websites. These URLs were supposed to be Permanent. The URL should have always pointed to the content that was there in the first place. But since I needed to reorder the serial numbers in order to get the archives in place, I ended up needing to let visitors know where they can find those new entries //if they want it.// That’s the tricky part. In the future, people using serach engines and newer web site will be on the page they expect to be. But people who have followed outdated links need to get to the information they are really looking for.

Wanna know how I dealt with it, and how JavaScript came into play? Read on…

So now, on pages that have the serial numbers below 400 will display a paragraph that tells people what the issue is and how to resolve it. For the first 6 months or so after this transition, that message will be on eveery page of the site, in the right hand column. Both messages do 3 things: 1) they let people know that there really is a problem, 2) they explain what the problem is and finally 3) they show how to fix the problem.

On the pages that specifically have this problem, I took the solution one step further. I provided a link, created on the fly with JavaScript that will display the link to the entry that has been renumbered. It’s a simple script; it finds the number of the current entry and adds 400 to it. Nothing too complex. However, the link is worthless for that do not have JavaScript. They will need to read the information about how to take care of it by hand.

In order to keep the JavaScripted link and associated information out of the browsers that will not be able to use it, I have written a JavaScript to write the link into the page. If the JavaScript is not executed by the browser, the link is never displayed. As well, the instructions on how to get to the entry that has been renumbered only discuss the link of JavaScript is running.

As an added bonus, I have placed some text inside a pair of NOSCRIPT tags that will explain to the user what would happen if JavaScript was enabled. This lets people understand what is going on and (if they have the option of enabling JavaScript) to understand what will happen once they refresh the page with the JavaScript enabled.

Of course, all of this could have been avoided entirely.

GreyMatter could have had a better method of creating URLS for it’s entries that would not have been so difficult to modify, or at least have been more flexible. Having the URLs based on the entry dates/time stamp or something else that would usually be unique to an entry.

There are other fixes. I could have simply restated the numbering at 1000. This would have been a good solution because then I would know that anytime someone wanted to visit a sub-1000 entry I could be sure that the system should shuttle the visitor up to the 1000+ version of the serial number. But I’m not sure if I would have had to create 1000 ‘blank’ entries in order to get the serial number count up that high. If I find the time, I might still do this and simply write off the month that things changed //again//.

Join me tomorrow when I discuss how many angels can dance on the head of a pin.

RSS feed for comments on this post · TrackBack URL

Leave a Comment