Tag Archives: Javascript

Link - How to hide and show initial content, depending on whether JavaScript support is available - Robert’s talk - Web development and Internet trends

How to hide and show initial content, depending on whether JavaScript support is available - Robert’s talk - Web development and Internet trends

The solution is to include a JavaScript file in the head part of the document. If JavaScript is enabled, it directly runs an anonymous function that in turn creates a link element which only contains CSS code to hide chosen elements if JavaScript is enabl

Dynamic radio buttons in IE

Man do I hate IE.

You’d think that creating a radio button in javascript would be as easy as something like this:

var radioButton = document.createElement('input');
radioButton.id = ‘RadioButtonList_1′;
radioButton.name = ‘RadioButtonList’;
radioButton.type = ‘radio’;
parentElement.appendChild(radioButton);

but, no - that doesn’t work, thanks to IE not allowing the name attribute to be set for dynamically created elements.
So, instead, you need to do something like this:

var radioButton;
try {
    // This is the only way you can set the “name” attribute in IE, but it will fail in other browsers
    radioButton = document.createElement(’<input id=”RadioButtonList_1″ name=”RadioButtonList” type=”radio” />’);
} catch() {
    // The above will fail if not in IE, so try it the correct way here
    radioButton = document.createElement(’input’);
    radioButton.id = ‘RadioButtonList_1′;
    radioButton.name = ‘RadioButtonList’;
    radioButton.type = ‘radio’;
}

Sidebar collapser… plugin?

I’ve had questions every now and then about how I do the sidebar collapsing thing (show / hide links) on my sidebar area. I have it running as a plugin, but I haven’t publicly released it yet (more on that later).

For those who don’t want to wait, you can always check out the SidebarCollapser.js file linked to this page; that’s really all there is to it. The file contains a script that will run when the page loads, and go through the sidebar and add the show/hide links to the appropriate sections.

One basic principle I try to adhere to is “unobtrusive javascript”, which means that the page should load and work fine if the browser does not support script (or has it disabled). The user should be able to use the basic functionality of the site without enabling javascript. Furthermore, (IMHO) they shouldn’t even see things that they can’t use, so the additional script-based functionality (in this case the show/hide links) should only even show up if their browser will be able to use them.

Like I said above, I’ve been thinking about packaging it up as a plugin, but I’m undecided about that since I don’t seem to have a lot of time lately to support and upgrade the ones I’ve already released, much less taking on new stuff. Aside from the time requirements for support, I’d also like to go through and refactor / clean up the code a bit before I’d release it anyway. Anyone is welcome to take it and adapt it to suit their own needs, but unfortunately I can’t take the time to package it up and release (and support) it as a plugin right now.

Why Firefox?

In response to Kristi’s question here, let me outline my personal take on why everyone should use a browser other than IE…
Read More »

Weighing in on Flock

Interesting article / discussion on the Flock browser here, including some responses from the developers themselves.

Personally, I’ve seen a bit of the Flock browser now, and I think my summary of it is “cute”. One of the main things I kind of felt about Flock from the beginning is something that the author of this post alludes to as well - Flock aims to provide a whole bunch of “solutions” for use in the “new” web (don’t get me started on the “Web 2.0″ label), but solutions are only usually really good when there’s a problem that they’re actually solving.

I kind of see the Flock craze as a similar thing to the Ajax craze right now: mostly fluff. Ever since someone gave the asynchronous javascript with XML technique that’s been around for years a fancy name, Ajax has become the cool thing to do in web dev. And don’t get me wrong, it’s certainly cool for some things, and I’m sure it will be the basis of a lot of the cool stuff we’ll see on the web in the next couple years; BUT most people right now are using it to do stuff that adds no additional functionality or usefulness to their existing web systems; like posting blog comments and refreshing the list, for example.

Flock kind of strikes me the same way; there’s nothing that Flock does that I’ve been saying “I wish I could do X in Firefox”. I know I might feel differently if I used delicious (which I don’t - another thing I don’t see the point of, for my use). Sure it does some things differently, but for me it’s not worth the switch.

Sidebar thoughts

I am coming to the realization that I have way to much stuff in my sidebar. It might be time to move to a 3 column layout, as well as cut some stuff out.

I am already planning on moving the links out to their own page, so they aren’t on every page (even though you can collapse them, as long as your browser supports javascript).

Any other suggestions?

Javascript tip

Firefox has been the best browser for developing and debugging javascript code for a while now, with the built-in DOM inspector, web developer toolbar, etc. This article on loading the JS console in the sidebar makes it even better.

Read my email

Alternate title: Popup navigation is evil

Jared: Thu, 28 Apr 2005 16:29:40 -0700

I’m blogging it right now.

Dan: Thu, 28 Apr 2005 16:22:00 -0700

You should blog on this, I wouldn’t mind at all.

Here’s the full conversation, in the correct order:
Read More »