阻止右键点击个浏览器兼容
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <!-- oncontextmenu="return false", 兼容safari --> <div style="width: 200px; height: 200px; background: gray;" id="oDiv" oncontextmenu="return false"></div> <script> let oDiv = document.getElementById('oDiv'); oDiv.oncontextmenu = 'return false'; oDiv.addEventListener('contextmenu', (e) => { if (e.preventDefault) { // W3c e.preventDefault(); } else { // IE window.event.returnValue = false; } return false; }) </script> </body> </html>