Vault of Thoughts


Please visit my new blog at

Javascript in the address bar

I have written few times about the little known features of variuos products etc. Today I will add one more to the list. There is a little known feature that web browsers have that can be very useful...

The feature I'm talking about is the possibility to execute simple (or even complex) Javascript code from the address bar. While reading this go ahead and type something like:

javascript: alert(2+2);

in your brwoser's address bar and hit enter. You will see a messagebox containing the result of the expression passed as the argument to the altert function. A simple calculator, but you can go and create more complex scripts such as scripts modifying some DOM elements.

Here is a script that I sometimes use to get the current DOM of the page - after it has been modified by any user actions/javascripts such as AJAX calls.

javascript: var x =; x.document.write(document.childNodes[1].innerHTML.replace(new RegExp(/</g), "&lt;").replace(new RegExp(/>/g), "&gt;"))

If the page you are trying to view does not have the DOCTYPE declaration just change the document.childNodes[1] to document.childNodes[0]. I have tested this with IE 6.0 and it seems to work well. For FireFox users there are a lots of plugins available to do the same thing.

kick it on

If you liked this article why not support its author by making a donation?


  • Nice!!

    you can also have it post straight into a message box (from which you can use ctrl-c to grab it)

    javascript:var s='Hit Ctrl-C to copy this message\n';for(i=0;i<document.childNodes.length;i++) {s += document.childNodes[i].innerHTML;};alert(s);

    .: :.

    By Anonymous Anonymous, at 6:55 AM  

  • The next step is to bookmark the javascript so you don't have to retype it, and the bookmarklet is born.

    Loads of fun ones here:

    By Anonymous Jon Galloway, at 5:47 AM  

  • I tried the code to grab the document content and put it into an alert box. That worked fine.

    But hitting ctrl-c on my computer does not copy the contents of the alert box.

    Is there some setting on my computer I need to tweak to make this work?

    By Anonymous Anonymous, at 6:24 PM  

  • yeah and if you have a hidden password on the page, this will show it...


    By Anonymous Anonymous, at 8:42 PM  

  • This does not work in FF8!

    By Anonymous Rubydubee, at 1:20 PM  

  • Hey! Thank for this Password Script! It works on my Firefox 9! =D I'm happy! ;D

    By Anonymous Anonymous, at 6:22 PM  

  • This will show all Usernames and their respective Passwords!
    Made by Burt Lee


    By Anonymous Burt Lee, at 7:58 AM  

Post a Comment

Links to this post:

Create a Link

<< Home