Jscript Versions Reported By Major Versions of Internet Explorer (For Use With Conditional Compilation)

Conditional Compilation is a handy, Internet Explorer specific method for forking bits of JavaScript. The nice thing about it is that real browsers don’t notice it at all. It just looks like a comment block to any non-IE browser. Which saves the rest of the world from even having to if (IE) { } else { } . I like that.

Anyway, we use it to fix some of IE’s shortcomings. One standard pattern is using it to fake the :hover pseudo-class on inputs in IE6. Something like this:

//IE6 HOVERS simplified// //this would be a bit different in protection //but you can see the idea /*@cc_on @*/
/*@if (@_win32)
var inputElements = document.getElementsByTagName("input");
var test = inputElements.length;
for (var i=0; i<test; i++) {
      if (inputElements[i].getAttribute("type") == "submit"){
            inputElements[i].onmouseover = inputElements[i].onfocus =  function(){
                  addClass(this, "hover");
            }
            inputElements[i].onmouseout = inputElements[i].onblur = function(){
                  removeClass(this, "hover");
            }
      };
}; /*@end @*/
//END IE6 HOVERS//

Continue reading “Jscript Versions Reported By Major Versions of Internet Explorer (For Use With Conditional Compilation)”

The JavaScript NodeList and You. Watch Where You Point That Thing, Soldier

I saw this tweet yesterday and was reminded , once again, of how misunderstood the return value of a DOM method like document.getElementsByTagName is. Normally, it doesn’t matter that folks don’t really understand the return value fully, because most of the time the code just works. Where it breaks is interesting, so it’s worth taking a look at it in a little bit of depth.

Typically people do things like this:

var anchors = document.getElementsByTagName('a'); 
for (var i = 0; i < anchors.length; i++) {
      anchors[i].addEventListener("click", beAwesome, false)
}

Common pattern. Get a list of the anchors on the page, loop through and add an event to each.

If asked, I’d be willing to bet most people would assume that the list they’re interacting with is an Array. It’s got a length and you can index it- that’s got to be an Array, right?

Surprise! 🙂
Continue reading “The JavaScript NodeList and You. Watch Where You Point That Thing, Soldier”

Have I Mentioned That The HTML5 DOCTYPE Makes Me Smile?

It does.

Why?

Well, I’ve been doing this job, at a very high level, for a long time and I couldn’t code this by hand if you paid me $50,000:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  

I understand it, and I can’t remember it. That’s basically gibberish to most people. There’s no way anyone is going to remember that string.

This? This I can code by hand and pretty much anyone can “get” what it’s doing:

<!DOCTYPE html >  

I do wonder if there’s been any backlash against that? I’ve seen a lot of backlash against HTML5 over the past year, but I can’t really remember anyone complaining about the doctype declaration.

I bet someone hates it.

Not me 🙂

Bing Launches Twitter Search (and I’m Writing About the Real Time Web Over At AWiderNet)

Mashable broke the story earlier today and withing a couple of hours Microsoft launched bing.com/twitter Web 2.0 Summit. First impression? I don’t like the look of the tag cloud.

tag-cloud

C’Mon, Microsoft, you can be cooler than that.

One thing I do like is the timing of it as I just wrote a big-ass article on the Real-Time Web over at AWiderNet.

Look at me being all topical.

Check it out and let me know what you think. Comments are always welcome.

I’m Excited About the New Google Analytics Engagement Goals Feature

Since I run so many content-centric sites, I’ve never really had much use for Google Analytics’ goals. It’s one thing when you’re doing lead generation or ecommerce. Those goals are clear and easy to define.

Someone filled out a form? Goal reached.

Someone hit a thank you page for purchasing a book? Goal reached.

For content sites, where the aim is engagement goals are tougher to define.
Continue reading “I’m Excited About the New Google Analytics Engagement Goals Feature”