Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript window.onrightclick? javascript

I created a very small script that creates an alert box saying "YOU CLICKED!" every time a person left clicks on the page, my problem is that i wish for it to occur upon right click too (this is for demonstration/experimentation purposes only). Here is my original script:

<script>
window.onclick=function() {alert("You clicked!");}
</script>
like image 574
Blake Myers Avatar asked Dec 21 '25 23:12

Blake Myers


1 Answers

Use oncontextmenu:

window.oncontextmenu = function() {
    alert(':)');
    return false; /* prevent context menu from popping up */
};
like image 121
pimvdb Avatar answered Dec 24 '25 20:12

pimvdb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!