页面定时自动刷新禁止右键F12代码

文章作者:技术宅 | 2021-11-04
字体大小:

采用javascript实现禁止右键和F12查看源代码,这是为了别人不看你的代码,对于不懂得人哦,如果老手是防不住的!

禁止F12代码:


 
  • <script type="text/javascript">
  •  
  • document.onkeydown = function () {
  • if (window.event && window.event.keyCode == 123) {
  • event.keyCode = 0;
  • event.returnValue = false;
  • return false;
  • }
  • };
  • </script>

禁止右键代码:


 
  • <script language="Javascript">
  • document.oncontextmenu=new Function("event.returnValue=false");
  • document.onselectstart=new Function("event.returnValue=false");
  • </script>

自动刷新代码:


 
  • <script language="JavaScript">
  • function re_fresh() {
  • window.location.reload();
  • }
  • setTimeout('re_fresh()',15000); //指定15秒刷新一次
  • </script>

方案二


 
  • <script type="text/javascript">
  • //屏蔽右键菜单
  • document.oncontextmenu = function (event){
  • if(window.event){
  • event = window.event;
  • }try{
  • var the = event.srcElement;
  • if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
  • return false;
  • }
  • return true;
  • }catch (e){
  • return false;
  • }
  • }
  • //屏蔽粘贴
  • document.onpaste = function (event){
  • if(window.event){
  • event = window.event;
  • }try{
  • var the = event.srcElement;
  • if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
  • return false;
  • }
  • return true;
  • }catch (e){
  • return false;
  • }
  • }
  • //屏蔽复制
  • document.oncopy = function (event){
  • if(window.event){
  • event = window.event;
  • }try{
  • var the = event.srcElement;
  • if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
  • return false;
  • }
  • return true;
  • }catch (e){
  • return false;
  • }
  • }
  • //屏蔽剪切
  • document.oncut = function (event){
  • if(window.event){
  • event = window.event;
  • }try{
  • var the = event.srcElement;
  • if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
  • return false;
  • }
  • return true;
  • }catch (e){
  • return false;
  • }
  • }
  • //屏蔽选中
  • document.onselectstart = function (event){
  • if(window.event){
  • event = window.event;
  • }try{
  • var the = event.srcElement;
  • if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
  • return false;
  • }
  • return true;
  • } catch (e) {
  • return false;
  • }
  • }
  • </script>

 

暂时关闭评论!
Copyright © 2019 技术宅 版权所有 关于我们| 法律声明| 免责声明| 广告服务| 联系我们| 投稿| 充值| 豫ICP备2023024979号