//Shield the right-click menu of the web page document.oncontextmenu=new Function("event. returnValue=false;""/> //Shield the right-click menu of the web page document.oncontextmenu=new Function("event. returnValue=false;"">
Home >Backend Development >PHP Problem >How to cancel right click in php
To cancel the right-click menu on the web page, we need to use JavaScript to achieve it.
The method is as follows:
Introduce a JavaScript file at the head of the HTML file, the code is as follows:
<script type="text/javascript"> //屏蔽网页右键菜单 document.oncontextmenu=new Function("event.returnValue=false;"); </script>
Add the onload attribute to the body tag of HTML to automatically run the script when the page loads.
<body onload="load()"> ... </body>
The JavaScript code is modified as follows:
<script type="text/javascript"> function load() { //屏蔽网页右键菜单 document.oncontextmenu=new Function("event.returnValue=false;"); } </script>
In PHP files, you can also use the above method to cancel the right-click menu. Just put the above code in the head tag before the PHP code block.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>取消右键菜单</title> <script type="text/javascript"> function load() { //屏蔽网页右键菜单 document.oncontextmenu=new Function("event.returnValue=false;"); } </script> </head> <body onload="load()"> <h1>PHP 取消右键菜单</h1> <p>当需要在网页上保护自己的内容不被复制、粘贴、保存时,可以使用 JavaScript 来取消右键菜单。</p> </body> </html>
The above is the method to cancel the right-click menu. The code is simple, easy to understand and easy to implement.
The above is the detailed content of How to cancel right click in php. For more information, please follow other related articles on the PHP Chinese website!