Saturday, October 8th, 2005


One problem I have encountered is that sometimes templates differ, and one person may have paragraph tags inside a form, with input elements inside them. Other people may have another setup, such as all input elements inside the one paragraph tag, except the comment box.

Sometimes, I needed to be able to find the form element that was the parent of a particular element, and sometimes this was it’s immediate parentNode, sometimes it was the grandparent node (node.parentNode.parentNode).

So I wrote this nice little function that uses recursion to find the parent that is a form. I’m fairly sure it works okay, and there’s even a little check that will return and explicit false if there is no parent form.

function getParentForm(node){
    if (node==document)
        return false;
    if (node.tagName!="FORM")
        return getParentForm(node.parentNode);
    else
        return node;
}
View Comments (0)   RSS Feed for Comments on this Post

JavaScript has a pretty neat feature. Lets say I have some functions that need to be run when the page has finished loading. Say, like replacing some encrypted email addresses with the gravatar they are associated with. Since you want all of your JavaScript to remain in the external.js file, and not have to add anything other than the one call to the file in the header of the page, you need a method of knowing when the page has finished loading.

By setting up as follows, you can do this:

window.onload = function () {
    // Put code or calls to functions in here
    SetupStuff();
}

This has a couple of disadvantages:

  1. If another script called after yours also has an assignment to window.onload, only their code will run.
  2. Alternately, if you are running after another script, you will replace any assignments they have made to window.onload.
  3. This will only be called when the whole page has run, including any images that need to be downloaded.

(more…)

View Comments (0)   RSS Feed for Comments on this Post

Had a good idea for a bookmarklet today: get a username/password for the current domain from bugmenot, and automatically add it into the fields!

I’ve got one that pops up a window: BugMeNot, but it would be cool if it interacted with the page.

View Comments (2)   RSS Feed for Comments on this Post

I didn’t realize this until the other day, but it’s possible to back up every post you’ve ever made using an offline client, such as the excellent ecto. I use the Mac version of this great program, and to back up every post I’ve ever made is as simple as:

  • Find out how many posts you have made.
  • Tell ecto to download this many recent posts.
  • Press the Refresh button.

(more…)

View Comments (12)   RSS Feed for Comments on this Post

I just listen to randmon music most of the time. But every now and then a weird series of tracks come up. The normal thing is that tracks theat we currently have in the car CD player play. But this one tops everything.

The Eagles, New Kid In Town comes on, and I switch over to iTunes Rater to rate it, as I like that song. Then I notice this:

The title of the previous song was “Johnny Come Lately”, words that are part of the chorus of “New Kid In Town”.

Almost as spooky as the bit in Metal Gear Solid 2 where stuff starts going bunkum, and the voice says:

You’ve been playing this video game for too long.
Turn the console off now.

This occurred at around 4am, so I was totally freaked. It was right, I had been playing the game for too long. Although this was actually part of the plot (trying to make Raiden[?] believe he is not real), I was convinced.

The Night Is A Blackbird • Augie MarchStrange Bird

View Comments (0)   RSS Feed for Comments on this Post