JavaScript Browser Hacks

Posted on DotNetBlocks See other posts from DotNetBlocks
Published on Thu, 23 Jun 2011 00:00:00 -0400 Indexed on 2011/06/23 8:28 UTC
Read the original article Hit count: 837

Filed under:
|

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
Source: http://www.openjason.com/2008/09/02/browser-hack-make-any-web-page-editable/

javascript:document.body.contentEditable='true'; 
document.designMode='on'; void 0;

Example 5: CHINESE DRAGON DANCING

Source: http://nzeyi.wordpress.com/2009/06/01/dwrajaxjavascript-hacks-the-secrets-of-javascript-in-the-adress-bar/

javascript:R=0;x1=0.1;y1=0.05;x2=0.25;y2=0.24;x3=1.6;
y3=0.24;x4=300;y4=200;x5=300;y5=200;DI=document.links;
DIL=DI.length;A=function(){for(i=0;i-DIL;i++){DI[i].style.
position='absolute';DI[i].style.left=Math.sin(R*x1+i*x2+x3)*x4+
x5;DI[i].style.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++;};
setInterval('A()',5);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
Source: http://forums.digitalpoint.com/showthread.php?t=767053

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

Learn more about JavaScript Browser Hacks.

© DotNetBlocks or respective owner

Related posts about JavaScript

Related posts about Tips