//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

How to cancel right click in php

PHPz
PHPzOriginal
2023-04-04 09:13:50783browse

To cancel the right-click menu on the web page, we need to use JavaScript to achieve it.

The method is as follows:

  1. Write a script file

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>
  1. Run the script when the page loads

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>
  1. Apply to PHP

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn