Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PreventDefault text selection context menu on mobile in browser

Tags:

javascript

How to disable context text selection menu in browser? Is it possible?

This is how text-selection-menu is look like:

enter image description here

like image 565
OnengLar Avatar asked May 29 '26 22:05

OnengLar


1 Answers

Another anwser on requirement of @OnengLar. Here is just a small trick to do that using js and html.

function clicked(event){
  event.preventDefault();
  //Custom popup here
  alert('Right clicked me');//For now just showing an alert
}
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<span oncontextmenu="clicked(event);">Select me and see my different behaviour</span>
</body>
</html>
like image 99
Programmerabc Avatar answered May 31 '26 13:05

Programmerabc



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!