IE8 Passes Acid2 Test

December 21st, 2007

Web developers, rejoice! Internet Explorer has passed the Acid2 Test.

JavaScript Object Detection Targeting IE 6 or IE 7

October 2nd, 2006

Today I found myself in an interesting dilemma. I had just spent the morning fine tuning some CSS menu styles, the left nav type with submenus. In my workplace, we only care about IE 6 and Firefox, we keep an eye on Safari, and we’re starting to care about IE 7. My styles were working quite well in all our target browsers, but then I turned my attention to IE 6.

The problem with IE 6 is that it does not support :hover on any element other than an anchor. Knowing I would have to write some JavaScript, I started by using the old document.all test in order to isolate IE; not the best, I know, but that’s another battle for another day.

The problem I encountered was this: the document.all test does not distinguish between IE 6 and IE 7. In other cases, that was fine, but here, I wanted to make sure that IE 7 used the CSS styles without any javascript. So off to google I went.

Unfortunately, I found nothing. After much digging, however, I discovered a combination of tests that solved my problem. First, I came across window.external. Using this isolates IE. The next thing I came across was typeof window.XMLHttpRequest. IE 6 returns undefined, while IE 7 (and Safari, by the way) returns object. (Firefox returns function.)

With these two bits of code, I cobbled together the following, which works well in my work environment:

if (window.external && (typeof window.XMLHttpRequest == "undefined")) {
// javascript targeting IE 6
}

Just change undefined to object to target IE 7. There may be better ways to do this, but since IE 5 is just a bad memory where I work, this solution is fine. My testing was with IE 6 and IE 7 RC.

So far, so good, though I have a feeling there may be a better way. I’d be interested in finding out if anyone has to do something similar in a situation where both IE 6 and IE 7 are target browsers but some javascript is intended for only one or the other.

Ma.gnolia Etc.: Plugin for WordPress

August 4th, 2006

Awhile back, I started using ma.gnolia to store my bookmarks online. I soon discovered that the site provides a code snippet you can insert into your WordPress templates that will display as many of your links as you like. Cool!

But it was a bit of javascript, and control over the exact output was limited and restrictive. Still, it wasn’t so bad, and I’ve been using it for several months now. What I really wanted, though, was a plugin for WordPress. Plugins are easy to use and usually easy to modify.
Quite recently, I discovered that just such a plugin has been created. I immediately downloaded it and immediately forgot about it. Until today. I took it for a test ride, and found it to be very simple to use. It was almost exactly what I had been wanting.
However, it was also outputting the links in a way that I didn’t like. Specifically, it was wrapping a DIV around the list of links. There’s nothing wrong with that, except that I didn’t want that. I just wanted a simple UL, and I wanted to be able to control via the function’s parameters whether or not to include the wrapper.

Fortunately, Barry Price, the author of this plugin, wrote it so that it is easy to modify. And that’s exactly what I did. I preserved the output as he wrote it, wrapper and all, while adding a parameter that allows you to specify if the output is meant to stand alone (i.e., use the wrapper) or not.

For clarity, I have renamed the modified plugin and function name. The only thing I have not done is add the ability to display the byline of the links, which the original javascript snippet from ma.gnolia did enable. Time allowing, I’ll add that later.

To use the ma.gnolia etc plugin, just insert the a call to the

magnoliaEtc('strUsername',blnStandalone,intNumberOfLinks)

into your WordPress template, where

  • strUsername is your ma.gnolia username,
  • blnStandalone is either true or false (true to include the wrapper, false to omit it), and
  • intNumberOfLinks indicates the number of links to display (this parameter is optional; omitting it will display 10 linnks).

So to use this function to display your five latest ma.gnolia links, simply insert it into your template:

< ?php magnoliaEtc('username',true,5); ?>

That’s all there is to it.

    • Download ma.gnolia etc v1.0 (8k) plugin for WordPress.
    • Installation: Unzip and place folder in your WordPress plugins directory.
    • Be sure to activate the plugin.

    The original plugin by Barry Price is available here.