This trick is not known by everyone though it is really simple.

The address bar

In the address bar, you simply write

javascript:/*some javascript code here*/;void(0);

As easy as that.

In fact, it's the same thing as creating a link that executes some javascript code.

<a href="javascript:alert('Some code from a link');">Execute code from javascript</a>

The only thing I add is the void(0); at the end of the code to avoid a “bug” that reloads the page.

Hey, if you want to write a bookmarklet, you'll probably use this technique.

Firebug

These days, you can't write javascript without using Firebug (apart if you are a javascript magician). You just can't. For the ones who don't know Firebug, I'll describe it in 7 words : javascript debugger, html inspector, css modifier, fun.

On the “Console” tag, there's one line beginning with “>>>” at the bottom. This is the javascript executer. If you click the red arrow at the end of the line, you have a multi-line executer.

I always use it to write and test the javascript snippets on this site.

What can I do with that?

Everything you want. In fact, I use it for these purpose :
  • write code snippet for Javascript Kata
  • write a bookmarklet
  • debug javascript on Firefox
  • have fun on other's sites

comments powered by Disqus