网页禁止右键 禁止F12 Jquery禁止F12 禁止右键菜单 包含 Jquery、Vue
- 网页禁止右键 禁止F12 JavaScript禁止F12 禁止右键菜单 js
- JavaScript 中
- Jquery 中
- Vue 中
这样设置通常是出于安全性或保护内容的目的,不想让别人看到源代码等信息
网页禁止右键 禁止F12 JavaScript禁止F12 禁止右键菜单 js
JavaScript 中
| <script> |
| |
| document.addEventListener('contextmenu', function (e) { |
| e.preventDefault(); |
| }); |
| |
| |
| document.onkeydown = function (e) { |
| if (e.which === 123 || e.key === "F12" || e.key === "Inspect") { |
| e.preventDefault(); |
| } |
| }; |
| <script> |
复制
Jquery 中
| |
| <script> |
| debugger |
| function checkForDevTools() { |
| |
| const element = new Image(); |
| element.__defineGetter__('id', function () { |
| |
| window.close(); |
| }); |
| window.close(); |
| console.clear(); |
| console.log(element); |
| } |
| |
| $(document).ready(function () { |
| checkForDevTools(); |
| }); |
| </script> |
| |
| <script> |
| |
| $(document).on('contextmenu', function (e) { |
| e.preventDefault(); |
| }); |
| |
| |
| $(document).on('keydown', function (e) { |
| if (e.which === 123 || e.key === "F12" || e.key === "Inspect") { |
| e.preventDefault(); |
| } |
| }); |
| </script> |
复制
Vue 中
将禁止右键和禁止F12键的逻辑放在mounted生命周期钩子中,以确保它们在组件加载后生效。
| <template> |
| <div> |
| <p>这是一个示例页面。</p> |
| </div> |
| </template> |
| |
| <script> |
| export default { |
| mounted() { |
| |
| document.addEventListener('contextmenu', (e) => { |
| e.preventDefault(); |
| }); |
| |
| |
| document.onkeydown = (e) => { |
| if (e.which === 123 || e.key === "F12" || e.key === "Inspect") { |
| e.preventDefault(); |
| } |
| }; |
| }, |
| }; |
| </script> |
| |
复制