Stupid Programmer – Javascript IE gotcha

Although I no longer code for my company, I did spend 7 years writing VB and Java code. I still do the occasional website and am fascinated by how this medium of programming is constantly pushing the boundaries of what is possible with a limited toolset.

One of my current “frameworks du jour” is MooTools and I have been using this to create some fun stuff for a piece of work. That piece of work requires that much of the content is editable, so I’ve separated that from the presentation framework and then needed to include that back into the page at rendertime.

So I setup a whole host of Ajax calls to get all the relevant content for each page, test it in Firefox and all works. Then I try in IE and it all fails “Internet Explorer cannot open the internet site, operation aborted

A quick google reveals this article from RyanGrant.net and I instantly realize that I have over-solutionised – and committed a no-no:

<div id=”mycontent”><script language=”javascript”> new Ajax(filename, {method: ‘get’, update: $(elementName)}).request(); </script></div>

Instead of

<div id=”mycontent”><!– #include file = “htm_file” –></div>

So effectively I was generating 10 x the number of HTTP requests rather than letting the server side include handle it and creating 1-2 HTTP connections. PLUS the inclusion of javascript within the page is not allowed by IE (but is by FF, Opera, etc).

Lesson learned. Don’t get carried away with the new box of toys.

Reminds me of the best line of code I ever reviewed by a contract developer:

If (x > 4 and x <6){ do something }

So basically he was checking to see If (x = 5){ do something} … geek.

Advertisements

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