Archive for the ‘JavaScript’ Category

workaround for entity bug (?) in tabber

Tuesday, February 6th, 2007

A user of my tabber script discovered that when his tab headings had an ampersand character like this:

<h2>Me &amp; My Shadow</h2>

Then the tab control displayed “&amp;” instead of a single ampersand character.

It looks like this occurs because the JavaScript DOM function document.createTextNode() does not convert entities. However, it looks like innerHTML does convert entities, so to fix your problem find the following line in tabber.js:


and replace with the following:

DOM_a.innerHTML = t.headingText;

I’ll think about this some more and if I can’t find any bad side effects I’ll add to the tabber code.

Including dojo the easy (buggy) way

Wednesday, January 10th, 2007

While trying out Dojo using the new easy include method, I found a weird JavaScript bug in IE6:

If you use a document.write() to write two script elements on the page, then instead of running the first script followed by the second script, IE apparently runs them both at the same time. This can cause an error if the second script calls a function that is defined in the first script.

The dojo bug and some test cases are in Bug #2280.

LazyScript (made up word of the day)

Tuesday, September 5th, 2006

LazyScript (n): a solution coded in JavaScript that should have been implemented with server-side coding. The resulting solution works in most browsers, but does not work when JavaScript is disabled, is not accessible, and does not appear in search engines. See also: kludge, hack

How to beg

Wednesday, May 3rd, 2006
dog begging

I provide some free open source software, and to help defray the costs of this website, I usually beg for PayPal donations.

Here’s a JavaScript function I use, attached to the download link, to annoy people into sending me a donation:

function begForMoney()
  if (!arguments.callee.stopBegging) {
    arguments.callee.stopBegging = true;
    alert("Please donate!");

Here’s how to attach it to a link. You can attach it to multiple links on the page, and it only triggers an alert the first time it is clicked.

<a href="" onclick="begForMoney()">Download</a>

FauxJAX: An AJAX Framework for Idiots

Thursday, April 13th, 2006
fake eyball

Introducing FauxJAX.

Want to get your hands on some crazy delicious Web 2.0 venture capital, but don’t have mad AJAX skills? If you can copy and paste, you too can have a website that looks oh-so two thousand and six!

Simply use our framework to display content on your site, and we’ll do the rest. Don’t worry about outdated server-side technology because FauxJax is beyond all that. Way beyond. Like in the next century, you have no idea.

Get FauxJAX today!

Three more things you should not do in JavaScript

Tuesday, April 11th, 2006

On the Yahoo! user interface blog I just saw their post “with Statement Considered Harmful“. Good advice.

Here are a few more things that I never do in JavaScript:

  1. Never use the “with” statement (as described above)
  2. Never use single line “//” comments. Use “/**/”. One day your code is going to be mangled and the newlines removed (perhaps by a crappy content management system), and suddenly your code will be commented out.


    // a comment

    After: (UH OH!)

    // a comment alert('ping!');
  3. Never omit the semi-colon after a statement. Again, this is to protect your code in case the newlines are removed, and to make the code easier to parse (by humans and machines).


    var t = 'ping!'

    After: (ERROR)

    var t = 'ping!' alert('ping!')

    This can be harder than it seems! For example, in the following example you should add a semi-colon after the closing brace:

    var myFunc =
    function() {
  4. Never omit the optional brackets { } around a statement. This can prevent some hard-to-debug errors when you add and remove code.


    if (true)

    Fixed: (UNAMBIGUOUS)

    if (true) {

To check your code for missing semicolons and brackets, use JSLint.

Bookmarklet to search current site using Google

Monday, April 10th, 2006

(This has been done before, but I’m putting my own spin on it.)

I often use Google to search a particular website, using “” and my search terms. It gets a bit tedious entering “”, so I made the following bookmarklet:

It prompts for the search terms, automatically adds the “site:” keyword and domain name, then goes to Google. You can select some text on the page before you click the bookmarklet, and your selected text will be used as the default search keywords.

For Firefox just drag-and-drop the link to your bookmarks toolbar. For IE, right-click the link then select “Add to Favorites…” (you might get a warning message since the bookmark contains javascript) then add it to your Links toolbar.

Inspired by: Search Bookmarklets

JavaScript tabbifier v1.7 new features

Monday, April 10th, 2006

I just released a new version of my JavaScript tab interface software.

New Features

  • Can automatically set a unique id for each tab navigation link, which allows you to individually style each tab.
  • Includes a “minimized” version of the code (with comments and whitespace removed, for extra-fast loading).