Web Development - Do A Quick Test Of A JavaScript Command In Your Browser's Address Bar

When you're in a rush, sometimes every second makes a difference. Creating a new Web page and testing it in different browsers--just to make sure you have the right syntax--can get wearisome when you're under a lot of pressure. However, most modern Web browsers allow you to test a limited amount of JavaScript right in the address bar where you normally type a URL. Just type the word "JavaScript" followed by a colon, and experiment to your heart's content. You can even use semicolons to write multiple lines of code. For example, the following typed in the address bar gives you a dialog box that says 3:

  • JavaScript:var x=34;alert(x)

You can also write to the screen, using window.status. (Even though that property normally writes to the status bar, it writes to the screen when you execute code from the address bar.) For instance, the following code in the address bar writes a bold number 4 on the screen:

  • JavaScript:var x=4;window.status = "" + x + ""

One last thing to keep in mind is that Gecko-based browsers (e.g., Netscape and Mozilla) and Opera leave your code in the address bar as is, whereas IE converts your spaces to "%20"--so it may be a little harder for you to see what you've typed.

Go back