Week of JS hacks

This week seems to have been filled with ridiculous Javascript hacks.

I came up with this one. I’m sure you can figure out what it does.

function send_mail(body,subject) {
  var mailwin = window.open("mailto:admin@example.com?subject="
      + subject + "&body=" + body);
  mailwin.close();
}

I have to give credit to Ben from Vidoop for this one. It’s actually part of a Firefox plugin (you can’t usually create Java objects in JS). Apparently if you try to create a Java object the Javascript will often stop evaling completely if Java is not installed. This nice little trick creates a separate thread to check for Java support, this way if the thread never returns, we assume it failed.

function checkJava() {
    var test = new java.util.LinkedList();
    if (test != null)
        vpwsJavaWorks = true;
    }
setTimeout(checkJava, 100);

I saved the best for last. This is more of a rant than a hack. The following line of Javascript works in IE 6.0.2900 but evaluates differently in IE 6.0.3790

    var GetArg = window.location.search.match('foo=([a-z]*)')[1];
Advertisements