网页屏蔽各种按键的代码分享

  • 内容
  • 相关

 有时候网页需要用到屏蔽功能,最常用的就是屏蔽查看代码和右键了,下面是一些常用的代码

<script> 
//屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键 
function document.oncontextmenu(){event.returnValue=false;}//屏蔽鼠标右键 
function window.onhelp(){return false} //屏蔽F1帮助 
function document.onkeydown(){ 
 if((window.event.altKey)&& 
 ((window.event.keyCode==37)|| //屏蔽Alt+方向键← 
 (window.event.keyCode==39))){ //屏蔽Alt+方向键→
 alert("不准你使用ALT+方向键前进或后退网页!"); 
 event.returnValue=false; 
 } if((event.keyCode==8)|| //屏蔽退格删除键 
 (event.keyCode==116)|| //屏蔽F5刷新键 
 (event.ctrlKey && event.keyCode==82)){ //Ctrl+R 
 event.keyCode=0; 
 event.returnValue=false; 
 } 
 if(event.keyCode==122){event.keyCode=0;event.returnValue=false;} //屏蔽F11 
 if(event.ctrlKey && event.keyCode==78)event.returnValue=false; //屏蔽Ctrl+n 
 if(event.shiftKey && event.keyCode==121)event.returnValue=false; //屏蔽shift+F10 
 if(window.event.srcElement.tagName=="A" && window.event.shiftKey) 
 window.event.returnValue=false; //屏蔽shift加鼠标左键新开一网页 
 if((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4 
 window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px"); 
 return false; 
 } 
if(window.event && window.event.keyCode == 123) {
  alert("F12被禁用");
  event.keyCode=0;
  event.returnValue=false;
 }
 if(window.event && window.event.keyCode == 13) {
  window.event.keyCode = 505;
 }
 if(window.event && window.event.keyCode == 8) {
  alert(str+"\n请使用Del键进行字符的删除操作!");
  window.event.returnValue=false;
 }
 } 
</script>

原文地址:http://www.qqssu.com/post-65.html

本文标签:

版权声明:若无特殊注明,本文皆为《秋白》原创,转载请保留文章出处。

本文链接:网页屏蔽各种按键的代码分享 - https://www.jqlab.cn/post-816.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

评论

58条评论
  1. avatar

    Karla Lv.1 Chrome 65.0.3325.162 Chrome 65.0.3325.162 Mac OS X 10.13.3 Mac OS X 10.13.3 回复

    If some one needs to be updated with most up-to-date technologies after
    that he must be go to see this web site and be up to
    date all the time.

    美国 纽约州伊利县威廉斯维尔村ColoCrossing有限公司

    1. avatar

      fun lunch recipes Lv.1 Chrome 65.0.3325.183 Chrome 65.0.3325.183 Mac OS X 10.13.4 Mac OS X 10.13.4 回复

      Hey! I'm at work browsing your blog from my new apple
      iphone! Just wanted to say I love reading through your blog and look forward to all your posts!
      Carry on the fantastic work!

      北美地区

      1. avatar

        fun dirt bike games Lv.1 Chrome 65.0.3325.181 Chrome 65.0.3325.181 Mac OS X 10.12.6 Mac OS X 10.12.6 回复

        Simply wish to say your article is as amazing. The clarity in your put up is just great and i can suppose you're an expert in this subject.
        Fine with your permission allow me to snatch your feed
        to stay updated with approaching post. Thanks a million and please continue the gratifying work.

        美国 纽约州伊利县威廉斯维尔村ColoCrossing有限公司

        1. avatar

          Malcolm Lv.1 Chrome 66.0.3359.181 Chrome 66.0.3359.181 Mac OS X 10.12.5 Mac OS X 10.12.5 回复

          What i do not understood is if truth be told how you are
          no longer really a lot more neatly-appreciated than you might be right now.
          You're very intelligent. You understand therefore considerably in the case of this topic, produced me
          for my part consider it from numerous varied angles.
          Its like men and women don't seem to be interested until it is something to do with Girl gaga!
          Your personal stuffs outstanding. At all times deal with it up!

          北美地区

          1. avatar

            fun journals Lv.1 Chrome 67.0.3396.62 Chrome 67.0.3396.62 Mac OS X 10.12.4 Mac OS X 10.12.4 回复

            Pretty component to content. I just stumbled upon your web site
            and in accession capital to say that I acquire in fact enjoyed account your weblog posts.
            Anyway I'll be subscribing on your augment or even I success you access consistently fast.

            美国 纽约州伊利县威廉斯维尔村ColoCrossing有限公司

            1. avatar

              Stacy Lv.1 Chrome 66.0.3359.181 Chrome 66.0.3359.181 Mac OS X 10.12.4 Mac OS X 10.12.4 回复

              Hola! I've been reading your site for a long time now and finally got the courage to go ahead and give you a shout out from  Porter Tx!
              Just wanted to tell you keep up the good work!

              美国 纽约州伊利县威廉斯维尔村ColoCrossing有限公司

              1. avatar

                fun to draw pictures Lv.1 Chrome 66.0.3359.139 Chrome 66.0.3359.139 Mac OS X 10.13.0 Mac OS X 10.13.0 回复

                Remarkable! Its really remarkable paragraph,
                I have got much clear idea regarding from this paragraph.

                美国

                1. avatar

                  Monika Lv.1 Internet Explorer 9.0 Internet Explorer 9.0 Windows 7 x64 Edition Windows 7 x64 Edition 回复

                  Wow that was strange. I just wrote an extremely
                  long comment but after I clicked submit my comment didn't appear.
                  Grrrr... well I'm not writing all that over again.
                  Anyways, just wanted to say excellent blog!

                  北美地区

                  1. avatar

                    Gus Lv.1 Chrome 66.0.3359.139 Chrome 66.0.3359.139 Mac OS X 10.13.2 Mac OS X 10.13.2 回复

                    It's an remarkable piece of writing in favor of all the web people; they will get advantage from it I
                    am sure.

                    美国

                    1. avatar

                      british-history.net Lv.1 Chrome 66.0.3359.139 Chrome 66.0.3359.139 Mac OS X 10.11.0 Mac OS X 10.11.0 回复

                      It's remarkable to go to see this site and reading the views
                      of all colleagues about this paragraph, while I am also zealous of getting experience.

                      美国