Fun JavaScript Snippets

Sam Deering

Hi guys, just a few JavaScript snippets I thought I would share with you.

JavaScript Space Mouse Script
Now you can play game on any web page, just copy and paste the javascript code given below in the url bar and hit enter. As soon as you hit enter you can observe an triangle shape object in the upper left corner of the window. Navigate it with the help of W, A and D keys and fire using Spacebar.

javascript:var%20s%20=%20document.createElement('script');s.type='text/javascript';document.body.appendChild(s);s.src='http://erkie.github.com/asteroids.min.js';void(0);


JavaScript Edit Page Directly Script
You easily edit any web page using this javascript. But when you refresh the page changes are lost.

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

JavaScript Infinite Alert Boxes Script
As soon as you run this javascript a infinite loop of alert boxes will open which cannot be stopped until you restart your web browser. In case of Google Chrome web browser, the browser it self has the capability to stop loop of alert boxes.
Warning: Obviously before running this close other tabs you have open (save your work!)

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

JavaScript URL Calculator Script
You can also use javascript for calculation purposes. Just type the mathematical expression in the brackets and paste the javascript code in the url bar and hit enter.

javascript: alert(4+5+6+7+(3*10));

Example: display your phone number:

javascript: alert('0'+(658*6)+''+(231228/9));

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • http://www.echteinfach.tv/ Harlem

    JavaScript Edit Page Directly Script is very useful! It is great to be able to edit before printing (esp. to remove commercials from tickets of flight companies that are otherwise printed) :)

  • http://www.javascriptreplace.com JS Replace

    Why would you need the Infinite Alert Boxes Script? I would think that would annoy some people. But then again if you’re trying to protect page or something that could be an interesting way of doing it.

    • jquery4u

      @ Harlem – Awesome script, I might do a separate post for it!

      @ JS Replace – Yes I agree it is pretty much a useless script, but fun nevertheless! :)

  • Pingback: 分かち合いの5つの面白いjavascriptコードの断片 | テクニカルブログ

  • Pingback: Share five interesting JavaScript code fragment