2023-05-22
演示站:https://ywenan.cc
// 禁用右键(防止右键查看源代码) window.addEventListener("contextmenu", function(e) { // 在当前事件种跑完操作后禁止打开右键菜单 e.preventDefault(); // 添加右键菜单 var menu = document.createElement("div"); menu.className = "menu"; menu.style.position = "fixed"; menu.style.top = e.clientY + "px"; menu.style.left = e.clientX + "px"; menu.innerHTML = ` <div class="ccRightNav" style="width: 200px; background: rgb(255, 255, 255); border-radius: 5px; position: fixed; padding: 5px 0px 0px; margin: 0px; z-index: 1200; box-shadow: rgba(50, 50, 90, 0.1) 0px 2px 35px; display: block; inset: auto auto auto auto;"> <li class="menu-item style="height: 29px; line-height: 29px; font-size: 12px; list-style: none; padding: 5px 0px; margin: 0px 0px 4px; text-decoration: none; background: none;"> <a href="https://ywenan.cc/" target="_blank" style="display: block; padding: 0px 25px; margin: 0px; color: rgb(17, 17, 17); text-decoration: none; font-size: 12px; cursor: pointer;">云文案</a></li> <li class="menu-item style="height: 29px; line-height: 29px; font-size: 12px; list-style: none; padding: 5px 0px; margin: 0px 0px 4px; text-decoration: none; background: none;"> <a href="https://www.jixs.cc" target="_blank" style="display: block; padding: 0px 25px; margin: 0px; color: rgb(17, 17, 17); text-decoration: none; font-size: 12px; cursor: pointer;">记录线</a></li> <li class="menu-item style="height: 29px; line-height: 29px; font-size: 12px; list-style: none; padding: 5px 0px; margin: 0px 0px 4px; text-decoration: none; background: none;"> <a href="https://www.jixs.cc/" target="_blank" style="display: block; padding: 0px 25px; margin: 0px; color: rgb(17, 17, 17); text-decoration: none; font-size: 12px; cursor: pointer;">工具箱</a></li> <li class="menu-item style="height: 29px; line-height: 29px; font-size: 12px; list-style: none; padding: 5px 0px; margin: 0px 0px 4px; text-decoration: none; background: none;"> <a href="https://www.jixs.cc/" target="_blank" style="display: block; padding: 0px 25px; margin: 0px; color: rgb(17, 17, 17); text-decoration: none; font-size: 12px; cursor: pointer;">资源库</a> </li> <hr style="border-top: none; border-right: none; border-bottom: 1px solid rgb(233, 233, 233); border-left: none; border-image: initial;"> <li class="qrBtn" style="height: 29px; line-height: 29px; font-size: 12px; list-style: none; padding: 5px 0px; margin: 0px 0px 4px; text-decoration: none; background: none;"> <a href="https://aaa.jishuaiwen.com/wx/Brand/Brand72/" target="_blank" style="display: block; padding: 0px 25px; margin: 0px; color: rgb(17, 17, 17); text-decoration: none; font-size: 12px; cursor: pointer;">微信公众号【伊人ya】</a></li> <li class="qrBox" style="height: 179px; line-height: 29px; font-size: 12px; list-style: none; padding: 0px; margin: 0px 0px 4px; text-decoration: none; width: 285px; max-width: 400px; max-height: 168px; position: absolute; bottom: 0px; border: 1px solid rgb(233, 233, 233); overflow: hidden; right: 200px; left: auto; display: none;"> <img src="/gpage/xcx-1.jpg" alt="微信二维码" style="width: 100%; height: 100%; margin-left: 0px; opacity: 1;"></li> </div> `; var style = document.createElement('style'); style.innerHTML = ` .qrBtn:hover .qrBox:hover .qrBtn .qrBox { display: block; } .menu-item { display: block; margin-bottom: 5px; padding: 8px; color: #333; text-decoration: none; cursor: pointer; } .menu-item:hover { background-color: #2affda; } .menu-item:last-of-type { border: none; } `; document.head.appendChild(style); // 将菜单添加到 DOM 中 document.body.appendChild(menu); document.addEventListener('click', function() { menu.style.display = 'none'; }, {once: true}); }); // 禁止键盘敲击事件(防止F12和shift+ctrl+i调起开发者工具) // 在按下 F12 或 Shift+Ctrl+I 时阻止默认事件 window.addEventListener('keydown', function(event) { if (event.keyCode === 123 || (event.ctrlKey && event.shiftKey && event.keyCode === 73)) { event.preventDefault(); alert('已禁用 F12 和 Shift+Ctrl+I'); return false; } });
在需要放置效果的页面添加这个-----放在<head>中间</head>
<script type='text/javascript' src='/static/js/xiaoguo.js'></script>
/static/js/xiaoguo.js 为js代码保存的路径
例如:
<!DOCTYPE html> <html> <head> <script type='text/javascript' src='/static/js/xiaoguo.js'></script> </head>
版权声明:本站所提供的文章、图片等内容均为用户发布或互联网整理而来,仅供学习参考,如有侵犯您的版权,请联系我们客服人员删除。