css.php

Into the strangeness

There’s a lot of strangeness writing JavaScript for the web. The edge cases are sometimes mind-bending. This is sometimes not the fault of JavaScript itself, but can be due to the other, non-JS things that the browser is doing.

I ran into such problems recently when modifying a widget that provides access to our library’s discovery service, OneSearch. I wanted the widget to open OneSearch in a new tab (shouldn’t be a big deal, right?), but oh boy did that open a can of worms.

The variety of behaviors that I got from different users of the widget was stunning. Sometimes it would open one tab, sometimes two, sometimes three tabs. Sometimes it would get caught by a pop-up blocker, sometimes not. I couldn’t pin the behavior down to any specific browser type, browser version, or OS. Some of my fixes worked for some users, but not for others.

I won’t go into the gory details, but I did solve the problem. Unfortunately, this was not by fully understanding what JavaScript and the browser were doing, but by walking back the changes I had made to my code until I located the problem, and then adjusting from there.

I remain in awe of the strangeness of JavaScript, and I walk carefully, fearfully, in its presence.

This entry was posted in javascript. Bookmark the permalink. Trackbacks are closed, but you can post a comment.

Post a Comment

You must be logged in to post a comment.

Need help with the Commons? Visit our
help page
Send us a message
Skip to toolbar