Solved: IE event – “this.parentNode.parentNode is null or not an object”

… it bloody-well is! This post was very nearly “Things that piss me off 5: Internet Explorer” (that one may yet come) but I thought a more descriptive title would help more people struggling with the same problem to find it.

Anyway: background.  I am writing a new feature for a Content Management System to allow users to upload files. With a simple bit of javascript I added a “+” button to allow them to add new rows to the form, allowing them to upload multiple files. It looks a bit like this:

Screenshot of Upload Images feature
Screenshot of Upload Images feature

Anyway, it would obviously be nice to allow the user to remove a row if they’ve added one or two too many. The obvious solution seems to be to add a “-”  button beside each. Easy, right?

Unfortunately Internet Explorer, as per usual, ballses everything up. Because each – button is created dynamically I have to add an EventListener using JavaScript code. No problem so far.

That event listener is a simple, one-line:

this.parentNode.parentNode.removeChild(this.parentNode);

As each row (the label, field itself (including button) and “-” link) is inside a div, the above code should remove that div and therefore remove the row. And it does… in Firefox. Try it in Internet Explorer and you get a message telling you “Error: ‘this.parentNode.parentNode’ is null or not an object”.

Whhhaaa?!

Don’t you just hate when you can easily find something your code claims it can’t? Am I the only one who screams “It’s right f**king there!!” at my monitor? In this case, the problem seems to boil down to IE’s supid, proprietary, fucked up way of attaching Event listeners. When you use Mozillas the W3C standard addEventListener method to attach a listener to an event, “this” in the event handler refers to the object which the event is called on. Obvious, yes?  However when you use IE’s attachEvent instead, IE doesn’t seem to act in the same way. Apparently, instead, IE sets “this” in an event handler to the window object instead of the calling/event object! Another good job from Micro$oft!

Apparently it’s can be overcome, but that involves a lot of code and I refuse in principle to do that much inelegant hacking for something so simple. It’s much easier (and principled) to do this:

IE error message: "Sorry, your browser doesn't support this function. This is probably because you're using Internet Explorer. www.getFirefox.com"
Not really a long-term solution, but bloody satisfying nonetheless.

Firefox 3 – Initial Impressions

I haven’t come across anything truly groundbreaking in Firefox 3, possibly because I’ve become accustomed to much of the feature set through the Betas and RCs, but there are one or two improvements that are quite useful (as well as a couple of regressions unfortunately).

Wee Niggles

First the bad. When you view Page Info from the context menu it doesn’t give a link to the CSS file in the Media tab any more. I was sure it was there in 2 and a quick google confirmed this. This really sucks – I can’t see why they’ve taken it out.

Secondly, when I was looking through the options to try and return the aforementioned CSS links, I discovered Firefox had decided it was going to automatically download any future updates when they were discovered (I promptly switched the option to “Ask me…”). Bad Firefox.

Magic Address Bar

The good is good though. It doesn’t seem like it at first, but to my mind the biggest improvement of all is the address bar. Sure they’ve added a “Most Visited” folder to your bookmarks toolbar which (shockingly, given the title) contains a list of the sites you visit most frequently, but the address bar has some great, if not immediately obvious, usability improvements.

Continue reading “Firefox 3 – Initial Impressions”

FireFox 3 Released Today

Looks like the excitement is a little bit premature. Not just yet, but at 6pm BST the newest version of Mozilla’s FireFox web browser will be released. Mozilla want Firefox 3 to break the record for the most downloads in 24 hours, which begs the question as to why they pissed off Australasia and half of Asia by promoting Download Day as today, 17th June, when they’re not making the new version available until 10am Pacific Time which means the aforementioned regions will not see the download released until it is 18th June there.

That’s without even considering yours truly and millions of other Europeans who will be finished their days work.

Good work Mozilla.

What’re you lookin’ at?

Well I thought it was interesting so here’s the top 10 posts on nerd. by number of views (based on the last 500 page hits courtesy of Statcounter.com).

  1. Review: Why the Netgear WG311 v3 Sucks (72)
    Slightly dodgy network card that Netgear don’t seem that fussed about fixing.

    Bad on XP, it got worse on Vista (see number 4).

  2. Playing iPod Video on Your TV (45)
    Seems to be a lot of people looking for instructions for the iPod Classic. Here’s a tip: sell it.
  3. Server application unavailable: installing IIS on .NET 2.0 (44)
    Seems to be a common problem. Sadly Microsoft’s error message is about as relevant as ever.
  4. Installing Vista (AKA More Netgear WG311 Misery) (31)
    Even more messed up. Thank goodness for Linksys!
  5. Thunderbird/Outlook/Google Calendar Integration (25)
    How to integrate your Thunderbird calendar at home with your Outlook in work, via Google Calendar.
  6. Orange Answerphone (Voicemail) Number for PAYG (23)
    Such a simple problem. Who knew it would be so hard to find?
  7. Stop Monitor.exe Hogging CPU (20)
    Why can’t people just give you a standard installation instead of trying to do everything for you? Help sounds good, until their useful tools start killing your PC.
  8. How to run IIS Web Server in Windows XP Home (20)
    Microsoft’s official line is it can’t be done, but it’s not that tricky.
  9. Making Firefox Scroll With Syanptics TouchPad (19)
    Discovering the solution to making Firefox scroll on my Acer Aspire laptop.
  10. NAS or Home Server (17)
    I deliberate over whether I can justify spending the extra to build or buy a home server before eventually deciding that a Linkstation Live will meet my needs for less than half the price.

nerd. links – Fix Firefox/Flash CPU Thrashing

I love FireFox, both as a web browser and as a web designer. I love it because it works, I love it for adhering (much better than IE ever will anyway) to web standards and I love it for the handy plugins that you can get.

I hate it though, for thrashing my CPU to 99% whenever I load some pages with flash animations in them. UnitedWebHosting which, as of this date, hosts this site (though probably not for long) is one that’ll do it. Today, I went to ZDnet UK only for a couple of Intel ads to do the same.

It seems like a bit of a joke that a company the size of Adobe (the makers of Flash: they write the plugin, not Mozilla) haven’t managed to resolve this, fairly major, bug. I’m sure they know about it, I mean different people seem to have been talking about since at least January last year.

FlashBlock inserts placeholders for Flash animationsObviously while FireFox is hogging 99% of your CPU there’s only 1% to share among the rest of the programs you have running, so Outlook and the rest didn’t have much of a hope of doing anything at all until I killed the FireFox process in task manager. As this wasn’t the first time this had happened, I decided to go hunting for a solution – which brings me to FlashBlock (hat-tip to The Idiot).

FlashBlock uses JavaScript to replace flash animations in web pages with placeholders (an empty square with a flash logo in the middle). Don’t worry though, clicking this will run the flash animation if you really want to see something (e.g. if you visit YouTube or another site where the primary content is encoded in Flash files). In fact you can even specify a ‘white-list’ of sites in which flash content will run automatically.

Making Firefox Scroll With Synaptics TouchPad

Even though, as a web designer, I hate Internet Explorer I’ve been using it regularly on my laptop more or less since I got it. The reason for this sad state of affairs was that Firefox wouldn’t recognise the scroll buttons on the Synaptics TouchPad and so I’d have to scroll using the cursor keys or the scroll bar on the right. This situation finally became untenable this morning though – I had two instances of Microsoft’s Visual Web Developer open and the machine seemed frustratingly slow to respond. A quick duke at Task Manager confirmed that this was because lots of memory was being used.

The Visual Web Developer program uses a lot of memory but I was surprised to find that Internet Explorer was actually using more at about 60MB. Firefox, also running at the time, was only using about 20MB so I decided it was time to fix the scrolling problem. I googled a bit and came across reports of people testifying that they solved the problem by downloading the newest drivers from Synaptics’ web site. This didn’t work for me though. Then I came across this forum post at Mozillazine which talked about changing a setting for the scroll buttons from “scroll selected item” to “scroll item beneath pointer”. Unfortunately this didn’t work for me either.

Here’s what did (after installing those new drivers):

  1. Double-click the touchpad icon in the system tray
  2. Ensure the correct device is selected in the Device Settings tab and click the Settings button
  3. Open the Buttons list and click ‘Scroll Up Button Action’
  4. Choose “Scroll the current window up” from the list.
  5. Click the ‘Scroll Down Button Action’ and choose ‘Scroll the current window down’ from the list.
  6. Apply/OK out.

Voila! Firefox now scrolls. I later discovered that someone else had replied to the above Mozillazine forum post advising just that, but I assure you I discovered it myself quite by accident.

Anyway, during the course of this fiddling I also discovered that you can use the right hand edge of your touch pad for scrolling. Just move your finger up or down the far right edge of your touch pad and the window scrolls. Unlike the scroll buttons, this did work in Firefox regardless of the above setting (though according to this KnowledgeBase entry, it may require the newest drivers), so if you’re having problems with Firefox scrolling with a Synaptics touchpad device, you should now have two solutions. Enjoy!