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 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));

Win an Annual Membership to Learnable,

SitePoint's Learning Platform

  • 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) :)

  • 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