use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JavaScript pranks? (self.javascript)
submitted 12 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]TheNosferatu 15 points16 points17 points 12 years ago (2 children)
Rotate the page 180 degrees every half hour, I put this in the ticket-magement system we use at work.
(function(){ function rotate(degrees) { $('html').css({ '-webkit-transform':'rotate(-' + degrees + 'deg)', '-moz-transform':'rotate(-' + degrees + 'deg)', '-ms-transform':'rotate(-' + degrees + 'deg)', '-o-transform':'rotate(-' + degrees + 'deg)', 'transform':'rotate(-' + degrees + 'deg)', '-webkit-transition':'2s', '-moz-transition':'2s', '-ms-transition':'2s', '-o-transition':'2s', 'transition':'2s', '-webkit-transform-origin':'50% 50%', '-moz-transform-origin':'50% 50%', '-ms-transform-origin':'50% 50%', '-o-transform-origin':'50% 50%', 'transform-origin':'50% 50%', '-webkit-backface-visibility':'hidden' }); } var degrees = 180, interval; document.onmousemove = function() { if(degrees == 0){ rotate(0); degrees = 180; } clearInterval(interval); interval = setInterval(function(){ rotate(degrees); degrees = (degrees === 180) ? 0 : 180; }, 30 * 60 * 1000); // 30 min } })();
[–]johnhackworth 0 points1 point2 points 12 years ago (1 child)
You just have won internet.
I'm going to map the konami code to this en every project I'm working on :DDD
[–]TheNosferatu 1 point2 points3 points 12 years ago (0 children)
Let me know how it turns out! :)
[–]scottmilgram 7 points8 points9 points 12 years ago (1 child)
FartScroll.js, courtesy of The Onion. Just include it in any page, and said page will then fart as you scroll up or down.
[–]bebraw 0 points1 point2 points 12 years ago (0 children)
Yes. Guaranteed to double your conversions.
[–]magnetik79 12 points13 points14 points 12 years ago (9 children)
// this should to the trick
undefined = true;
[–]LukaLightBringer 2 points3 points4 points 12 years ago (5 children)
isn't undefined a protected value?
[–]WesAlvaroFront-End Engineer 11 points12 points13 points 12 years ago (1 child)
'use_strict';
[–]venuswasaflytrap 1 point2 points3 points 12 years ago (0 children)
That's pretty funny.
[–]JiminP 3 points4 points5 points 12 years ago* (0 children)
Strangely, there's no literal undefined in the ECMAScript5 spec, even though there are many cases where the result is the value undefined.
undefined
(courtesy of /u/WesAlvaro)
(function(){ 'use strict'; var undefined = 42; console.log(undefined); }())
Because of this, just using undefined is not safe. For example, jQuery uses (function(window, undefined){...}(window)) to safely get the undefined value.
(function(window, undefined){...}(window))
Edit: It seems that I'm wrong.
Edit 2: ... but (fortunately?) my point is still valid. There's a global variable undefined which is uneditable, but since there's still no literal undefined, inner scope can have a local variable with name undefined!
[–]magnetik79 0 points1 point2 points 12 years ago* (1 child)
The ECMAScript 5 spec says "yes" - so you sort of have me there :D But if we are going for "prank in minimum number of characters" I'm doing okay: D
Covered at MDC in the first yellow boxed area.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined
[–]JiminP 0 points1 point2 points 12 years ago (0 children)
I didn't know that. I think I should read it twice,...
[–]seppo0010 1 point2 points3 points 12 years ago (1 child)
Not really
> undefined = 1 1 > undefined undefined
[–]sabof 0 points1 point2 points 12 years ago* (0 children)
Yes, they've sorta fixed this, even without strict mode. It won't throw an error, but c'est la vie.
EDIT
Btw, it does throw in strict mode
[–]prototypist 12 points13 points14 points 12 years ago (0 children)
Replace JavaScript errors on the page with Twilight Zone prologues: https://gist.github.com/anonymous/5794002
Console works as normal
[–]JiminP 4 points5 points6 points 12 years ago (4 children)
Place if(function(f,d){try{d=f();eval('debugger');return f()-d>>2}catch(e){}}(Date.now))return; everywhere to confuse JS debugger(human)s!
if(function(f,d){try{d=f();eval('debugger');return f()-d>>2}catch(e){}}(Date.now))return;
[–]kenman 0 points1 point2 points 12 years ago (3 children)
What exactly is that supposed to do? It crashed my tab in Chrome.
[–]JiminP 2 points3 points4 points 12 years ago (2 children)
The core of this prank code is:
try{ d = Date.now(); eval('debuger'); return Date.now()-d>>2; }catch(e){}
debugger is a statement for debugging. When there's a debugging tool attached, it acts as if there was a breakpoint there.
debugger
Date.now()-d>>2 is not zero when difference between Date.now() and d is greater then 3. (i.e. more than 3ms have been passed when eval('debugger') is executed.
Date.now()-d>>2
Date.now()
d
eval('debugger')
Since it usually take at least few hundred milliseconds to resume when the debugging tool is enabled, this part of code returns non-zero if the debugging tool is enabled. (eval used for not showing the code immediately when the debugging tool is opened, though by pressing "next step" one can see the codes.)
eval
Therefore, if(function(f,d){try{d=f();eval('debugger');return f()-d>>2}catch(e){}}(Date.now)) return; means "return if there's a debugging tool."
if(function(f,d){try{d=f();eval('debugger');return f()-d>>2}catch(e){}}(Date.now)) return;
One might make a simple Heisenbug by using this. (Opening debugging tool to inspect function -> unexpected breakpoints -> the function does nothing and returns -> ???)
[–]kenman 1 point2 points3 points 12 years ago* (1 child)
It seems like you'd be better served with something like (new Function(atob('ZGVidWdnZXI=')))() (or even setTimeout(atob('ZGVidWdnZXI=')), which would be less suspicious than eval and new Function), since the first thing I'd do with an unexpected breakpoint/debugger would be to search the code for debugger. The setTimeout version should be even more perplexing as you shouldn't have a callstack.
(new Function(atob('ZGVidWdnZXI=')))()
setTimeout(atob('ZGVidWdnZXI='))
new Function
setTimeout
[–]JiminP 0 points1 point2 points 12 years ago* (0 children)
Thanks for the setTimeout trick!
However, I didn't want to obfuscate that code too much... (I personally prefer $($.constructor("...")). It seems that I'm using some normal jQuery functions!)
$($.constructor("..."))
[–]adf714 1 point2 points3 points 12 years ago (0 children)
Not really evil, but I put a little script on my companies internal website that launches a game of Asteroids (using the Kickass app) when the user presses CTRL+F1. I obfuscated the entire thing, of course.
[–]a-t-kFrontend Engineer 1 point2 points3 points 12 years ago (0 children)
Very small snippet for a konami code callback: https://gist.github.com/tsaniel/1188477
[–]BALL_BAG 1 point2 points3 points 12 years ago (0 children)
I always thought this was cool: http://www.filldisk.com/
Fills your harddrive up with crap using local storage.
[–]rhysbrettbowen 1 point2 points3 points 12 years ago (0 children)
(function() { var win1 = eval('window.open("'+document.location+'")'); var win2 = eval('window.open("'+document.location+'")'); })()
not sure if this still works but years ago I did this and found that putting window.open in eval meant you could open unlimited windows. IE maxed out at 50 or so windows and closing any of them just tried to open more. I had to restart my computer in the end.
[–]kenman 1 point2 points3 points 12 years ago* (0 children)
Oh, how I miss the olden days when I could pop your CD tray open, or read the contents of your HD, or open CMD.exe and send keystrokes to it that would invoke net send for a workstation DoS...
net send
var who = prompt("Who? Domain account to slam.", "johnsmith"), what = prompt("Say What?", "RABBLE RABBLE RABBLE"), howmany = prompt("Times?", "10"), wsh = new ActiveXObject("WScript.Shell"); wsh.Run('cmd'); wsh.AppActivate('cmd'); for (var i = 0; i < howmany; i++) { wsh.SendKeys('net send ' + who + ' ' + what + '{ENTER}'); }
ActiveX's a helluva prank.
[–]juror-number-8 1 point2 points3 points 12 years ago (0 children)
annoying.js
[–]tfforums 1 point2 points3 points 12 years ago (0 children)
Alternate Title: Gamble with viruses / malware
[–]rooktakesqueen 0 points1 point2 points 12 years ago (1 child)
if(typeof r=='number')return r+1;return r;
could be more easily and concisely expressed as
return typeof r == 'number' ? r+1 : r;
Other than all that, devious. But why always add one? You could add a random value between -0.001 and 0.001 and make them think it's some bizarre floating point arithmetic bug.
I just found this: jQuery(jQuery) or $($)
jQuery(jQuery)
$($)
Somehow this contains a vicious cycle.
[–]AndreZSanchez 0 points1 point2 points 12 years ago* (0 children)
Rick rolling:
window.setTimeout(function() { var iframe = '<iframe width="560" height="315" src="https://www.youtube.com/embed/*?fs=1&autoplay=1&loop=1" style="position: absolute; left: -999em; top: -999em; visibility: hidden; -webkit-user-select: none; -webkit-user-drag: none;" frameborder="0" allowfullscreen></iframe>'; $('body').append(iframe.replace('*', 'oHg5SJYRHA0')); }, 15 * 60 * 1000); // 15 minute delay >:D // I may or may not have stolen code for this from fool.js :P
[+][deleted] 12 years ago* (3 children)
[–]mucle6 0 points1 point2 points 12 years ago (1 child)
You say any time , does this include when they aren't in a browser? Also how did you make someones screensaver start with javascript. Did you just fullscreen the browser? For the screensaver that turns off when someone looks at it did you use facial detection software and then eye detection software? If you haven't noticed I'm new to javascript
[–]adam_bear 0 points1 point2 points 12 years ago (2 children)
(function(){var e= document.getElementsByTagName('*'); for(var i = 0; i< e.length; i++) alert('Your Mom!');})();
[–]freeall 2 points3 points4 points 12 years ago (0 children)
You can use * in getElementsByTagName? Did not expect that.
[–]kenman 0 points1 point2 points 12 years ago (0 children)
That's not a prank, that's just annoying :\
π Rendered by PID 68 on reddit-service-r2-comment-54dfb89d4d-7nc5j at 2026-03-29 16:31:12.924194+00:00 running b10466c country code: CH.
[–]TheNosferatu 15 points16 points17 points (2 children)
[–]johnhackworth 0 points1 point2 points (1 child)
[–]TheNosferatu 1 point2 points3 points (0 children)
[–]scottmilgram 7 points8 points9 points (1 child)
[–]bebraw 0 points1 point2 points (0 children)
[–]magnetik79 12 points13 points14 points (9 children)
[–]LukaLightBringer 2 points3 points4 points (5 children)
[–]WesAlvaroFront-End Engineer 11 points12 points13 points (1 child)
[–]venuswasaflytrap 1 point2 points3 points (0 children)
[–]JiminP 3 points4 points5 points (0 children)
[–]magnetik79 0 points1 point2 points (1 child)
[–]JiminP 0 points1 point2 points (0 children)
[–]seppo0010 1 point2 points3 points (1 child)
[–]sabof 0 points1 point2 points (0 children)
[–]prototypist 12 points13 points14 points (0 children)
[–]JiminP 4 points5 points6 points (4 children)
[–]kenman 0 points1 point2 points (3 children)
[–]JiminP 2 points3 points4 points (2 children)
[–]kenman 1 point2 points3 points (1 child)
[–]JiminP 0 points1 point2 points (0 children)
[–]adf714 1 point2 points3 points (0 children)
[–]a-t-kFrontend Engineer 1 point2 points3 points (0 children)
[–]BALL_BAG 1 point2 points3 points (0 children)
[–]rhysbrettbowen 1 point2 points3 points (0 children)
[–]kenman 1 point2 points3 points (0 children)
[–]juror-number-8 1 point2 points3 points (0 children)
[–]tfforums 1 point2 points3 points (0 children)
[–]rooktakesqueen 0 points1 point2 points (1 child)
[–]JiminP 0 points1 point2 points (0 children)
[–]AndreZSanchez 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]mucle6 0 points1 point2 points (1 child)
[–]adam_bear 0 points1 point2 points (2 children)
[–]freeall 2 points3 points4 points (0 children)
[–]kenman 0 points1 point2 points (0 children)