How to execute javascript code directly in your browser
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.
Firebug has a javascript executer on the console page (the red arrow).

If you click on the button at the right of the executer (the yellow arrow), you’ll end up with 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


How do you debug JS in IE using Firebug? Isn’t Firebug only for FF?
Firebug is Firefox only! But every serious programmer knows you can’t use IE to debug
Firebug’s got a decent JS executer - but the Shell bookmarklet wipes the floor with it : http://www.squarefree.com/bookmarklets/webdevel.html#shell
one-word: code-completion
Thanks Si, these are cool tools!
If you want to debug in IE, or Safari for that matter, try Firebug lite.
@Adam
I had a look at Firebug Lite. It is cool but I naively thought it would have an integrated debugger.
The question is : can we have an IE debugger (apart of Visual Studio) that reproduces the same kind of debugging than Firebug?
I never used the debugger in firebug but if you want a debugger for IE, you could use MS Script Debugger but the problem is that you need to be genuine. For information on debugging IE, you may look here:
(http://blogs.msdn.com/ie/archive/2004/10/26/247912.aspx)
Can anyone explain why or how can javascript codes are executable in the address bar of a web borwser?
As I said in the post :
===========
In fact, it’s the same thing as creating a link that executes some javascript code.
Execute code from javascript
===========
javascript: is a pseudo-protocol implemented by browsers in the early days of the web.
>>Everything you want. In fact, I use it for these purpose :
>> * debug javascript on IE
>>>Dan (maintainer of Javascript Kata) May 1 2007 at 09:50:17
>>>Firebug is Firefox only! But every serious programmer knows
>>>you can’t use IE to debug
HUH??? If you are using it on FF how are you debugging on IE?
Dan, perhaps you could recommend Firebug Lite for all the people asking to debug in Ineternet Explorer. You can debug in IE, it’s just much harder.
Also, the page reload isn’t a bug as you claimed. It’s the output of the function you called. Using the javascript psuedo-protocol effectively turns the browser into the console, therefore “javascript:(2+2)” will output “4″ just as it should. The void function just tells the location field to have no output so the page isn’t rewritten.
@James
thanks for the info.
@Chad
Like James said, have a look at Firebug Lite. It doesn’t have all the features from the real Firebug but it can be handy.
I know that Microsoft offers a javascript debugger that can be installed on your computer but I never worked with it and I don’t know what it’s worth. If you try it, tell us about it…
I appreciate the recommendation, but I think you are misunderstanding my question. I am not asking for ways to debug in IE. I am asking for you to explain what you meant in the original post when you stated that you used firebug to debug javascript for IE.
@Chad
Oops… I made a terrible mistake. I meant “debug javascript on Firefox”. It is now changed.
LOL Ahh the mystery is solved
I was hoping there was some amazing feature that let firebug work with IE magically.