JavaScript Browser Hacks

by DNB 23. June 2011 00:00

Recently during one of my client side scripting classes, I was trying to show my students some basic examples of JavaScript as an introduction to the language.  My first basic example was to show an alert box using JavaScript via the address bar. The student’s reaction to my browser hack example really caught me off guard in a good way. After programming with a language for close to 10 years you start to lose the "Awe Cool!" effect that new learners of a language experience when writing code. New learns of JavaScript are the reason why I created this post. Please enjoy.

Note: Place JavaScript in to address bar and then press the enter key.

Example 1: JavaScript Alert box displaying My name: John Doe

Javascript:alert('My name: \n John Doe') ;

Example 2: JavaScript alert box displaying name entered by user.

javascript:alert('My name: \n ' + prompt('Enter Name','Name')) ;

Example 3: JavaScript alert box displaying name entered by user, and then displays the length of the name.

javascript:var name= prompt('Enter Name','Name'); alert('My name: \n ' + 
name); alert(name.length);

If you notice, the address bar will execute JavaScript on the current page loaded in the browser using the Document Object Model (DOM). Additionally, the address bar will allow multiple lines to be executed sequentially even though all of the code is contained within one line due to the fact that the JavaScript interpreter uses the “;” to indicate where a line of ends and a new one begins.

After doing a little more research on the topic of JavaScript Browser Hacks I found a few other cool JavaScript hacks which I will list below.

Example 4: Make any webpage editable

document.designMode='on'; void 0;




Example 6: Reveal content stored in password protected fields

javascript:(function(){var s,F,j,f,i; s = “”;
F = document.forms; for(j=0; j

Example 7: Force user to close browser window

javascript:while(1){alert('Restart your brower to close this box!')}

Learn more about JavaScript Browser Hacks.

Tags: , , , ,

JavaScript | Tips

Pingbacks and trackbacks (1)+

Comments are closed

Most comments