HDD Killers

Six JavaScript Features

Posted on Thursday 24 November 2005

I just read the blogs I link to in my sidebar, all good stuff I can assure you, however I would like to make particular mention of a site that isn’t on the list called “Wait till I come!” that was linked to on Jona’s site. I found something rather troubling on that site, and it wasn’t just that he spelt the title wrong (it’s ’til, not till!). It was a particular blog entry called “Six JavaScript features we do not need any longer”.

I’ll start off by saying that out of all of his points, I agree with the first and second and semi-agree with the fifth and sixth. I think it’s best if I run through them all individually and explain my reasoning.

  1. document.write – Like I said, I agree with him here. The DOM can be used to add in content in anywhere on the page so there’s no need for document.write.

  2. <noscript></noscript> – Here I also agree, it’s easy enough to manipulate the existing content with JavaScript if you want it to be displayed in a different way or (for some reason) not displayed at all, therefore there is no need for <noscript>.

  3. href="javascript: …", onclick="javascript:" – I’d like to clear up here that there is no need for javascript: in the onclick event handler, but there IS a valid use for javascript: in the href. It’s called a bookmarklet and bookmarklets can be very useful. A bookmarklet is basically a one-line JavaScript that you can store as a bookmark and then run it on any page. For example, if you really like the font Georgia, you could bookmark the following link, and then activate it on any page that you like.

    Bookmark for Georgia.

    Clicking on it will just run the JavaScript on the current page, but bookmarking it will allow you to run the code on any page. Obviously it won’t work for browsers with JavaScript disabled or not supported, so perhaps the link ought to be created with JavaScript in the first place, but it will still require the javascript: to appear in the href attribute of the link.

  4. onclick=”void(0)” – This follows on nicely from the last point, because in the bookmarklet link I actually USED void(0);. If I didn’t use void(0); then it wouldn’t work, in the case of that bookmarklet, you would be taken to a page that simply said Georgia on it. Using return false as a substitute for void(0); will simply cause a script error. However, in event handlers, return false should always be used instead of void(0);, the only valid use for void(0); is in the href after a bookmarklet.

  5. document.all , document.layers, navigator.userAgent – Here I semi-agree, document.all and document.layers is used by some people to check for ye olde IE DOM and Netscape DOM, if(document.all){ some IE code }. However, Firefox will now return true to document.all and will try and execute the IE code (and fail). Apart from that, there’s no excuse for not using the W3C DOM and then letting the older browsers fall back on the non-JavaScript support that your site should have anyway.

    On the other hand, navigator.userAgent is still useful in stat tracking. The stat tracking software that I use (Mint) collects user agent information with JavaScript in order to differentiate between browsers and web crawlers. It’s not perfect as not everyone has JavaScript enabled, and in my opinion it would be better to collect as much information as possible on the server-side, but that’s the way it is so I guess it still has a use.

  6. onmouseover="myCall('I','pity','the','foo',1233,'I aint going on no plane')" – Semi-agreeing again, I would like to remind you of the reasoning as to why this is bad.

    Anything crucial to the user experience that you generate via JavaScript needs to be in the document anyways – for users without JavaScript. Reusing this markup is a lot easier, cleaner and more maintainable than sending a lot of parameters. If there is any reason to send parameters, a simple “this” does the trick in most of the cases, as you can navigate through the DOM from there.

    Well the first sentence is definately true and I agree completely with that part of it. However sometimes it is necessary to provide a few “hooks” for the JavaScript to work with, in which case you are not creating some extra content, but perhaps you have hidden a section of content with JavaScript and now need to reveal it onmouseover, in which case you may need to pass the ID of the element you wish to reveal to the function. It needn’t be onmouseover though, it could be onclick or onblur.

    A lot of the time it’s true that using the “this” keyword is enough, I use it myself quite a lot, but sometimes it’s just not enough, and in those situations passing a few extra parameters to a function isn’t wrong. The only time it is wrong is when you are supply extra content that would be relevent to users without JavaScript.

Anyway, that’s enough about webdevelopment now. A quick summary of what else has happened since I last blogged. I found out that to download the Windows Server 2003 image I had to submit all of my TOTALLY GENUINE details again, then add the image to my shopping cart, then click next a lot of times and wait for some painfully slow loading pages to load, then I got an email with a link in it to a download and also an activation code. After all that kerfuffle I finally have the image on my PC and need only to burn it to disc.

I also played on Doom 3 earlier, and actually finished it. Finally, after over a year I finally got round to completing it. I always got bored after playing for so long, but this afternoon I started playing again and battled all the way through to the end, w00t for me.

I wrote this entire blog entry before I even had a title, seriously. I’m still writing and I haven’t even got a slight idea what the title might be.


  1.  
    Thursday 24th November 2005 | 10:49 pm
     
    Jonathan Fenocchi's Globally Recognised Avatar

    I think that document.write() and still have some practical uses, but 99% of the time they are a bad choice. Other than that, I agree with your agree/disagree statements.

    Oh yeah, and it’s proper to use “till” instead of “’til.” From http://www.answers.com/till

    USAGE NOTE Till and until are generally interchangeable in both writing and speech, though as the first word in a sentence until is usually preferred: Until you get that paper written, don’t even think about going to the movies.•Till is actually the older word, with until having been formed by the addition to it of the prefix un–, meaning “up to.” In the 18th century the spelling ’till became fashionable, as if till were a shortened form of until. Although ’till is now nonstandard, ’til is sometimes used in this way and is considered acceptable, though it is etymologically incorrect.

  2.  
    Friday 25th November 2005 | 2:19 am
     
    David's Globally Recognised Avatar

    Hmm, didn’t know that. The only uses for the word till that I knew were to mean cash register and ploughing.

    Yeah, I guess it can be handy to use document.write somtimes, such as using it to write out a bookmarklet link. document.write can be replaced with a bit of DOM though, and yeah It involves some slightly longer code, but it works with application/xhtml+xml.

  3.  
    Friday 25th November 2005 | 10:11 pm
     
    lilcrazyfuzzy's Globally Recognised Avatar

    Hmm, didn’t know that. The only uses for the word till that I knew were to mean cash register and ploughing.
    must be an american thing :p

    btw, did you see, did you see? i got my gravatar (after a whole week!)

  4.  
    Ben Rogers
    Saturday 26th November 2005 | 3:23 am
     
    Ben Rogers's Globally Recognised Avatar

    No you didn’t, fuzz, it’s still absent.

  5.  
    Saturday 26th November 2005 | 4:32 am
     
    Robert F.'s Globally Recognised Avatar

    Hey, you can put “Till” on us. It’s from Middle English, us Americans brought it with us from England. Don’t try to excuse your ignorance. 😛

    I agree with you David on all your points. What’s wrong with javscript: as a URL protocol? The data: protocol is a standard, but technically it’s not linking to a document, as it is the document. Same idea with the javascript: protocol.

  6.  
    josh
    Tuesday 31st July 2007 | 7:41 pm
     
    josh's Globally Recognised Avatar

    “#
    – Here I also agree, it’s easy enough to manipulate the existing content with JavaScript if you want it to be displayed in a different way or (for some reason) not displayed at all, therefore there is no need for .
    #”

    I disagree. The reason to use is so that browsers without javascript (enabled) can render the content you would want to be rendered only in that scenario.
    I don’t understand how otherwise manipulating the content with javascript is going to work if javascript itself doesn’t.

  7.  
    Thursday 20th September 2007 | 4:52 pm
     
    David's Globally Recognised Avatar

    I don’t think you understood me Josh. I was saying, make the page look like how you want for people without JavaScript, then for those with JavaScript, modify what’s there to look like how you want it to look for those with JavaScript. By doing it that way, noscript is not needed.

Sorry, the comment form is closed at this time.