Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Created April 3, 2016 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JavaScript-Packer/9968664d2139dd3096164aac034fb36b to your computer and use it in GitHub Desktop.
Save JavaScript-Packer/9968664d2139dd3096164aac034fb36b to your computer and use it in GitHub Desktop.
Replace the right click menu on your webpage using JavaScript!
<html><head><title>Right Click Context Menu JavaScript Replacement - WHAK.com</title></head><body bgcolor="silver"><h1>TOP</h1><h3>Right Click Menu In JavaScript</h3><hr size="7000" color="gray">
<script>
function a(b){c=document.all?event.clientX+document.body.scrollLeft:document.a?b.x+window.pageXOffset:b.clientX+window.pageXOffset;d=document.all?event.clientY+document.body.scrollTop:document.a?b.y+window.pageYOffset:b.clientY+window.pageYOffset}var e,f,g,c=0,d=0;void 0!=document.addEventListener?document.addEventListener("mousemove",a,!0):document.a&&document.captureEvents(Event.b|Event.c|Event.f);document.onmousemove=a;document.oncontextmenu=function(){return!1};document.onmousedown=function(b){3==b.which&&(document.getElementById("contextmenu").style.left=c+"px",document.getElementById("contextmenu").style.top=d+"px",document.getElementById("contextmenu").style.visibility="visible")};document.onmouseup=function(b){1==b.which&&(document.getElementById("contextmenu").style.visibility="hidden")};e=250,g=document.createElement("DIV");g.id="contextmenu";e||(e=120);g.style.width=e+"px";
f='<div style="padding:4px;margin:2px;opacity:0.7;left:10px;top:-4px;border-style:double;border-width:15px;">\
<font color="#565656" size="-2">Right Click Menu by <a href="http://www.whak.com" target="_top" title="WHAK it" alt="WHAK">WHAK</a>!</font><br>\
<u style="color:blue;cursor:hand" title="Reload Page" onclick="window.location.reload();">Refresh</u><br>\
<u style="color:blue;cursor:hand" title="Go Back" onclick="history.go(-1);">Back</u><br>\
<u style="color:blue;cursor:hand" title="Go Forward" onclick="history.go(1);">Forward</u><br>\
<u style="color:blue;cursor:hand" title="Back to top" onclick="window.scroll(0,0);">Top of page</u><br>\
<u style="color:blue;cursor:hand" title="Bottom" onclick="window.scrollTo(0,document.body.scrollHeight);">Bottom of page</u><br>\
<a href="http://www.make-gifs.com" title="Make animated GIFs online" alt="Animated GIF Maker" target="_blank">Make-GIFs.com</a><br>\
<a href="http://www.make-a-meme.com" title="Make memes online" alt="Meme Maker" target="_blank">Make-A-Meme.com</a><br>\
</div>';g.innerHTML=f;g.style.position="absolute";g.style.left="0px";g.style.top="0px";g.style.visibility="hidden";g.style.overflow="hidden";g.style.padding="4px";g.style.backgroundColor="#ffffff";g.style.border="1px solid #6a6868";document.body.appendChild(g);delete g;
</script><h1>BOTTOM</h1></body></html>
@JavaScript-Packer
Copy link
Author

Here is a dataURI/dataURL for you to test it in your web browser:

data:text/html,%3Chtml%3E%3Chead%3E%3Ctitle%3ERight%20Click%20Context%20Menu%20JavaScript%20Replacement%20%2D%20WHAK%2Ecom%3C%2Ftitle%3E%3C%2Fhead%3E%3Cbody%20bgcolor%3D%22silver%22%3E%3Ch1%3ETOP%3C%2Fh1%3E%3Ch3%3ERight%20Click%20Menu%20In%20JavaScript%3C%2Fh3%3E%3Chr%20size%3D%227000%22%20color%3D%22gray%22%3E%0A%3Cscript%3E%0Afunction%20a%28b%29%7Bc%3Ddocument%2Eall%3Fevent%2EclientX%2Bdocument%2Ebody%2EscrollLeft%3Adocument%2Ea%3Fb%2Ex%2Bwindow%2EpageXOffset%3Ab%2EclientX%2Bwindow%2EpageXOffset%3Bd%3Ddocument%2Eall%3Fevent%2EclientY%2Bdocument%2Ebody%2EscrollTop%3Adocument%2Ea%3Fb%2Ey%2Bwindow%2EpageYOffset%3Ab%2EclientY%2Bwindow%2EpageYOffset%7Dvar%20e%2Cf%2Cg%2Cc%3D0%2Cd%3D0%3Bvoid%200%21%3Ddocument%2EaddEventListener%3Fdocument%2EaddEventListener%28%22mousemove%22%2Ca%2C%210%29%3Adocument%2Ea%26%26document%2EcaptureEvents%28Event%2Eb%7CEvent%2Ec%7CEvent%2Ef%29%3Bdocument%2Eonmousemove%3Da%3Bdocument%2Eoncontextmenu%3Dfunction%28%29%7Breturn%211%7D%3Bdocument%2Eonmousedown%3Dfunction%28b%29%7B3%3D%3Db%2Ewhich%26%26%28document%2EgetElementById%28%22contextmenu%22%29%2Estyle%2Eleft%3Dc%2B%22px%22%2Cdocument%2EgetElementById%28%22contextmenu%22%29%2Estyle%2Etop%3Dd%2B%22px%22%2Cdocument%2EgetElementById%28%22contextmenu%22%29%2Estyle%2Evisibility%3D%22visible%22%29%7D%3Bdocument%2Eonmouseup%3Dfunction%28b%29%7B1%3D%3Db%2Ewhich%26%26%28document%2EgetElementById%28%22contextmenu%22%29%2Estyle%2Evisibility%3D%22hidden%22%29%7D%3Be%3D250%2Cg%3Ddocument%2EcreateElement%28%22DIV%22%29%3Bg%2Eid%3D%22contextmenu%22%3Be%7C%7C%28e%3D120%29%3Bg%2Estyle%2Ewidth%3De%2B%22px%22%3B%0Af%3D%27%3Cdiv%20style%3D%22padding%3A4px%3Bmargin%3A2px%3Bopacity%3A0%2E7%3Bleft%3A10px%3Btop%3A%2D4px%3Bborder%2Dstyle%3Adouble%3Bborder%2Dwidth%3A15px%3B%22%3E%5C%0A%3Cfont%20color%3D%22%23565656%22%20size%3D%22%2D2%22%3ERight%20Click%20Menu%20by%20%3Ca%20href%3D%22http%3A%2F%2Fwww%2Ewhak%2Ecom%22%20target%3D%22_top%22%20title%3D%22WHAK%20it%22%20alt%3D%22WHAK%22%3EWHAK%3C%2Fa%3E%21%3C%2Ffont%3E%3Cbr%3E%5C%0A%3Cu%20style%3D%22color%3Ablue%3Bcursor%3Ahand%22%20title%3D%22Reload%20Page%22%20onclick%3D%22window%2Elocation%2Ereload%28%29%3B%22%3ERefresh%3C%2Fu%3E%3Cbr%3E%5C%0A%3Cu%20style%3D%22color%3Ablue%3Bcursor%3Ahand%22%20title%3D%22Go%20Back%22%20onclick%3D%22history%2Ego%28%2D1%29%3B%22%3EBack%3C%2Fu%3E%3Cbr%3E%5C%0A%3Cu%20style%3D%22color%3Ablue%3Bcursor%3Ahand%22%20title%3D%22Go%20Forward%22%20onclick%3D%22history%2Ego%281%29%3B%22%3EForward%3C%2Fu%3E%3Cbr%3E%5C%0A%3Cu%20style%3D%22color%3Ablue%3Bcursor%3Ahand%22%20title%3D%22Back%20to%20top%22%20onclick%3D%22window%2Escroll%280%2C0%29%3B%22%3ETop%20of%20page%3C%2Fu%3E%3Cbr%3E%5C%0A%3Cu%20style%3D%22color%3Ablue%3Bcursor%3Ahand%22%20title%3D%22Bottom%22%20onclick%3D%22window%2EscrollTo%280%2Cdocument%2Ebody%2EscrollHeight%29%3B%22%3EBottom%20of%20page%3C%2Fu%3E%3Cbr%3E%5C%0A%3Ca%20href%3D%22http%3A%2F%2Fwww%2Emake%2Dgifs%2Ecom%22%20title%3D%22Make%20animated%20GIFs%20online%22%20alt%3D%22Animated%20GIF%20Maker%22%20target%3D%22_blank%22%3EMake%2DGIFs%2Ecom%3C%2Fa%3E%3Cbr%3E%5C%0A%3Ca%20href%3D%22http%3A%2F%2Fwww%2Emake%2Da%2Dmeme%2Ecom%22%20title%3D%22Make%20memes%20online%22%20alt%3D%22Meme%20Maker%22%20target%3D%22_blank%22%3EMake%2DA%2DMeme%2Ecom%3C%2Fa%3E%3Cbr%3E%5C%0A%3C%2Fdiv%3E%27%3Bg%2EinnerHTML%3Df%3Bg%2Estyle%2Eposition%3D%22absolute%22%3Bg%2Estyle%2Eleft%3D%220px%22%3Bg%2Estyle%2Etop%3D%220px%22%3Bg%2Estyle%2Evisibility%3D%22hidden%22%3Bg%2Estyle%2Eoverflow%3D%22hidden%22%3Bg%2Estyle%2Epadding%3D%224px%22%3Bg%2Estyle%2EbackgroundColor%3D%22%23ffffff%22%3Bg%2Estyle%2Eborder%3D%221px%20solid%20%236a6868%22%3Bdocument%2Ebody%2EappendChild%28g%29%3Bdelete%20g%3B%0A%3C%2Fscript%3E%3Ch1%3EBOTTOM%3C%2Fh1%3E%3C%2Fbody%3E%3C%2Fhtml%3E

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment