Right Click Color Flash
A visual deterrent. When a user tries to right-click, the page background instantly flashes a warning color (like Red) before returning to normal, signaling that the action is prohibited.
Right-Click Here
The box will flash red instead of showing a menu.
Copy the Script
<script>
function flashColor() {
var original = document.body.style.backgroundColor;
document.body.style.backgroundColor = "#ff0000"; // Flash Red
setTimeout(function() {
document.body.style.backgroundColor = original;
}, 100); // Duration in ms
return false;
}
document.oncontextmenu = flashColor;
</script>
Frequently Asked Questions
The script temporarily changes the 'document.body.style.backgroundColor' property to red, then uses 'setTimeout' to revert it back to white after a few milliseconds.
Flashing colors can be harmful to users with photosensitive epilepsy. You should use this effect very cautiously or stick to a simple static color change.
Yes. The script returns 'false' to the contextmenu event, suppressing the menu while simultaneously triggering the visual effect.