webcam exception: the multiple-page-versions trap

<http://webcam.exception.nl/> doesn't refresh the picture correctly every 30 seconds in Opera.

This is a quite common mistake: they have two different versions of the page. Depending on what browser you use, you will get either a MSIE-version with JavaScript or an alternate version. (They even say so in the source – if you load it in IE and view source you can find the text "MSIE detected" – the version Opera gets says "NO MSIE detected"). The JavaScript they send IE is used to re-load the image only and add a little countdown that tells you how many seconds are left to the reload happens. The alternate version will re-load the entire page with a META refresh tag.

It is always sad to see such clumsy solutions because the webmaster easily could have written the page in a way that would let the JavaScript automatically detect the browser's capability and adapt to virtually any browser. (Actually, all the script really needs is a browser that supports document.images – that means pretty much all browsers since Netscape 3!! No reason at all to limit the script to IE only..)

Yes, I said "easily". For simple scripts like this, cross-browser compatibility is easy. Of course if you're writing a GMail-type full-blown web application it's not easy to be cross-browser compatible but most scripts out there are a magnitude simpler and JavaScript has a built-in feature called "object detection" that makes it easy to let the script adapt automatically to any browser.

That's the promise of the Web: write once – view anywhere! If you're making things any more complicated than that, you are doing something wrong.

Advertisements

One thought on “webcam exception: the multiple-page-versions trap

  1. Some further comments that I left out of the main post to make it shorter and snappier 🙂

    The page causes JavaScript error messages in non-IE browsers because they try to call a function that only exists in the IE-version:

    onLoad="setTimeout(&quot;reloadImg()&quot;, 30000)"

    reloadImg is defined in the script they send IE and doesn't exist for the other browsers. (As a side note, this is the first time I've seen HTML entities used inside the JavaScript string in an inline event handler. I didn't even know it was possible but Opera seems to handle it fine.. It might be safer to use normal ' signs in case other browsers are less tolerant..)

    For whatever reason, the re-load does not work in neither IE nor Opera for me – the picture just disappears on reload in both because the server seems to send an empty file when the browser re-requests the picture.. That seems to be a server-side problem and not the fault of any of the browsers.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s