JS屏蔽功能类(屏蔽F5,退格键,空格键……)

JS屏蔽功能类(屏蔽F5,退格键,空格键……)

1.屏蔽功能类<br /><br />1.1&nbsp;屏蔽键盘所有键<br />&lt;script&nbsp;language=&quot;javascript&quot;&gt;<br />&lt;!--<br />function&nbsp;document.onkeydown(){<br />event.keyCode&nbsp;=&nbsp;0;<br />event.returnvalue&nbsp;=&nbsp;false;<br />}<br />--&gt;<br />&lt;/script&gt;<br /><br />1.2&nbsp;屏蔽鼠标右键<br /><br />在body标签里加上oncontextmenu=self.event.returnvalue=false<br /><br />或者<br /><br />&lt;script&nbsp;language=&quot;javascript&quot;&gt;<br />&lt;!--<br />function&nbsp;document.oncontextmenu()&nbsp;<br />{&nbsp;<br />return&nbsp;false;&nbsp;<br />}&nbsp;<br />--&gt;<br />&lt;/script&gt;<br /><br />function&nbsp;nocontextmenu()<br />{&nbsp;<br />if(document.all)&nbsp;{<br />event.cancelBubble=true;<br />event.returnvalue=false;&nbsp;<br />return&nbsp;false;&nbsp;<br />}<br />}<br /><br />或者<br /><br />&lt;body&nbsp;onmousedown=&quot;rclick()&quot;&nbsp;oncontextmenu=&nbsp;&quot;nocontextmenu()&quot;&gt;<br /><br />&lt;script&nbsp;language=&quot;javascript&quot;&gt;<br />&lt;!--<br />function&nbsp;rclick()<br />{<br />if(document.all)&nbsp;{<br />if&nbsp;(event.button&nbsp;==&nbsp;2){<br />event.returnvalue=false;<br />}<br />}<br />}<br />--&gt;<br />&lt;/script&gt;<br /><br /><br />1.3&nbsp;屏蔽&nbsp;Ctrl+N、Shift+F10、F5刷新、退格键<br /><br />&lt;script&nbsp;language=&quot;javascript&quot;&gt;<br />&lt;!--<br />//屏蔽鼠标右键、Ctrl+N、Shift+F10、F5刷新、退格键<br />function&nbsp;window.onhelp(){return&nbsp;false}&nbsp;//屏蔽F1帮助<br />function&nbsp;KeyDown(){<br />if&nbsp;((window.event.altKey)&amp;&amp;<br />((window.event.keyCode==37)||&nbsp;//屏蔽&nbsp;Alt+&nbsp;方向键&nbsp;&larr;<br />(window.event.keyCode==39))){&nbsp;//屏蔽&nbsp;Alt+&nbsp;方向键&nbsp;&rarr;<br />alert(&quot;不准你使用ALT+方向键前进或后退网页!&quot;);<br />event.returnvalue=false;<br />}<br /><br />/*&nbsp;注:这还不是真正地屏蔽&nbsp;Alt+&nbsp;方向键,<br />因为&nbsp;Alt+&nbsp;方向键弹出警告框时,按住&nbsp;Alt&nbsp;键不放,<br />用鼠标点掉警告框,这种屏蔽方法就失效了。以后若<br />有哪位高手有真正屏蔽&nbsp;Alt&nbsp;键的方法,请告知。*/<br /><br />if&nbsp;((event.keyCode&nbsp;==&nbsp;8)&nbsp;&amp;&amp;&nbsp;<br />(event.srcElement.type&nbsp;!=&nbsp;&quot;text&quot;&nbsp;&amp;&amp;&nbsp;<br />event.srcElement.type&nbsp;!=&nbsp;&quot;textarea&quot;&nbsp;&amp;&amp;&nbsp;<br />event.srcElement.type&nbsp;!=&nbsp;&quot;password&quot;)&nbsp;||&nbsp;//屏蔽退格删除键&nbsp;<br />(event.keyCode&nbsp;==116)||&nbsp;//屏蔽&nbsp;F5&nbsp;刷新键<br />(event.ctrlKey&nbsp;&amp;&amp;&nbsp;event.keyCode==82)){&nbsp;//Ctrl&nbsp;+&nbsp;R<br />event.keyCode=0;<br />event.returnvalue=false;<br />}<br />if&nbsp;((event.ctrlKey)&amp;&amp;(event.keyCode==78))&nbsp;//屏蔽&nbsp;Ctrl+n<br />event.returnvalue=false;<br />if&nbsp;((event.shiftKey)&amp;&amp;(event.keyCode==121))&nbsp;//屏蔽&nbsp;shift+F10<br />event.returnvalue=false;<br />if&nbsp;(window.event.srcElement.tagName&nbsp;==&nbsp;&quot;A&quot;&nbsp;&amp;&amp;&nbsp;window.event.shiftKey)&nbsp;<br />window.event.returnvalue&nbsp;=&nbsp;false;&nbsp;//屏蔽&nbsp;shift&nbsp;加鼠标左键新开一网页<br />if&nbsp;((window.event.altKey)&amp;&amp;(window.event.keyCode==115)){&nbsp;//屏蔽Alt+F4<br />window.showModelessDialog(&quot;about:blank&quot;,&quot;&quot;,&quot;dialogWidth:1px;dialogheight:1px&quot;);<br />return&nbsp;false;}<br />}<br />/*&nbsp;另外可以用&nbsp;window.open&nbsp;的方法屏蔽&nbsp;IE&nbsp;的所有菜单<br />第一种方法:<br />window.open(&quot;你的.htm&quot;,&nbsp;&quot;&quot;,&quot;toolbar=no,location=no,directories=&nbsp;no,menubar=no,scrollbars=no,resizable=yes,status=no,top=0,left=0&quot;)<br />第二种方法是打开一个全屏的页面:<br />window.open(&quot;你的.asp&quot;,&nbsp;&quot;&quot;,&nbsp;&quot;fullscreen=yes&quot;)<br />*/<br />//--&gt;<br />&lt;/script&gt;<br /><br />1.4屏蔽浏览器右上角&ldquo;最小化&rdquo;&ldquo;最大化&rdquo;&ldquo;关闭&rdquo;键<br /><br />&lt;script&nbsp;language=javascript&gt;<br />function&nbsp;window.onbeforeunload()<br />{<br />if(event.clientX&gt;document.body.clientWidth&amp;&amp;event.clientY&lt;0||event.altKey)<br />{<br />window.event.returnvalue&nbsp;=&nbsp;&quot;&quot;;<br />}<br />}<br />&lt;/script&gt;<br /><br />或者使用全屏打开页面<br /><br />&lt;script&nbsp;language=&quot;javascript&quot;&gt;<br />&lt;!--<br />window.open(www.32pic.com,&quot;32pic&quot;,&quot;fullscreen=3,height=100,&nbsp;width=400,&nbsp;top=0,&nbsp;left=0,&nbsp;toolbar=no,&nbsp;menubar=no,&nbsp;scrollbars=no,&nbsp;resizable=no,location=no,&nbsp;status=no&quot;);<br />--&gt;<br />&lt;/script&gt;<br /><br />注:在body标签里加上onbeforeunload=&quot;javascript:return&nbsp;false&quot;(使不能关闭窗口)<br /><br />1.5屏蔽F5键<br /><br />&lt;script&nbsp;language=&quot;javascript&quot;&gt;<br />&lt;!--<br />function&nbsp;document.onkeydown()&nbsp;<br />{&nbsp;<br />if&nbsp;(&nbsp;event.keyCode==116)&nbsp;<br />{&nbsp;<br />event.keyCode&nbsp;=&nbsp;0;&nbsp;<br />event.cancelBubble&nbsp;=&nbsp;true;&nbsp;<br />return&nbsp;false;&nbsp;<br />}<br />}<br />--&gt;<br />&lt;/script&gt;<br /><br />1.6屏蔽IE后退按钮<br /><br />在你链接的时候用&nbsp;&lt;a&nbsp;href=&quot;javascript:location.replace(url)&quot;&gt;<br /><br />1.7屏蔽主窗口滚动条<br /><br />在body标签里加上&nbsp;style=&quot;overflow-y:hidden&quot;<br /><br />1.8&nbsp;屏蔽拷屏,不断地清空剪贴板<br /><br />在body标签里加上onload=&quot;setInterval('clipboardData.setData(\'Text\',\'\')',100)&quot;<br /><br />1.9&nbsp;屏蔽网站的打印功能<br /><br />&lt;style&gt;<br />@media&nbsp;print&nbsp;{<br />*&nbsp;{&nbsp;display:&nbsp;none&nbsp;}<br />}<br />&lt;/style&gt;<br /><br />1.10&nbsp;屏蔽IE6.0&nbsp;图片上自动出现的保存图标<br /><br />方法一:<br />&lt;META&nbsp;HTTP-EQUIV=&quot;imagetoolbar&quot;&nbsp;CONTENT=&quot;no&quot;&gt;<br />方法二:<br />&lt;img&nbsp;galleryimg=&quot;no&quot;&gt;<br /><br />1.11&nbsp;屏蔽页中所有的script<br /><br />&lt;noscrript&gt;&lt;/noscript&gt;<br /><br /><br />2.表单提交验证类<br /><br /><br />2.1&nbsp;表单项不能为空<br /><br />&lt;script&nbsp;language=&quot;javascript&quot;&gt;<br />&lt;!--<br />function&nbsp;CheckForm()<br />{<br />if&nbsp;(document.form.name.value.length&nbsp;==&nbsp;0)&nbsp;{<br />alert(&quot;请输入您姓名!&quot;);<br />document.form.name.focus();<br />return&nbsp;false;<br />}<br />return&nbsp;true;<br />}<br />--&gt;<br />&lt;/script&gt;<br /><br />2.2&nbsp;比较两个表单项的值是否相同<br /><br />&lt;script&nbsp;language=&quot;javascript&quot;&gt;<br />&lt;!--<br />function&nbsp;CheckForm()<br />if&nbsp;(document.form.PWD.value&nbsp;!=&nbsp;document.form.PWD_Again.value)&nbsp;{<br />alert(&quot;您两次输入的密码不一样!请重新输入.&quot;);<br />document.ADDUser.PWD.focus();<br />return&nbsp;false;<br />}<br />return&nbsp;true;<br />}<br />--&gt;<br />&lt;/script&gt;<br /><br />2.3&nbsp;表单项只能为数字和&quot;_&quot;,用于电话/银行帐号验证上,可扩展到域名注册等<br /><br />&lt;script&nbsp;language=&quot;javascript&quot;&gt;<br />&lt;!--<br />function&nbsp;isNumber(String)<br />{&nbsp;<br />var&nbsp;Letters&nbsp;=&nbsp;&quot;1234567890-&quot;;&nbsp;//可以自己增加可输入值<br />var&nbsp;i;<br />var&nbsp;c;<br />if(String.charAt(&nbsp;0&nbsp;)=='-')<br />return&nbsp;false;<br />if(&nbsp;String.charAt(&nbsp;String.length&nbsp;-&nbsp;1&nbsp;)&nbsp;==&nbsp;'-'&nbsp;)<br />return&nbsp;false;<br />for(&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;String.length;&nbsp;i&nbsp;++&nbsp;)<br />{<br />c&nbsp;=&nbsp;String.charAt(&nbsp;i&nbsp;);<br />if&nbsp;(Letters.indexOf(&nbsp;c&nbsp;)&nbsp;&lt;&nbsp;0)<br />return&nbsp;false;<br />}<br />return&nbsp;true;<br />}<br />function&nbsp;CheckForm()<br />{<br />if(!&nbsp;isNumber(document.form.TEL.value))&nbsp;{<br />alert(&quot;您的电话号码不合法!&quot;);<br />document.form.TEL.focus();<br />return&nbsp;false;<br />}<br />return&nbsp;true;<br />}<br />--&gt;<br />&lt;/script&gt;<br /><br /><br />2.4&nbsp;表单项输入数值/长度限定<br /><br />&lt;script&nbsp;language=&quot;javascript&quot;&gt;<br />&lt;!--<br />function&nbsp;CheckForm()&nbsp;<br />{<br />if&nbsp;(document.form.count.value&nbsp;&gt;&nbsp;100&nbsp;||&nbsp;document.form.count.value&nbsp;&lt;&nbsp;1)<br />{<br />alert(&quot;输入数值不能小于零大于100!&quot;);<br />document.form.count.focus();<br />return&nbsp;false;<br />}<br />if&nbsp;(document.form.MESSAGE.value.length&lt;10)<br />{<br />alert(&quot;输入文字小于10!&quot;);<br />document.form.MESSAGE.focus();<br />return&nbsp;false;<br />}<br />return&nbsp;true;<br />}<br />//--&gt;<br />&lt;/script&gt;<br /><br />2.5&nbsp;中文/英文/数字/邮件地址合法性判断<br /><br />&lt;SCRIPT&nbsp;LANGUAGE=&quot;javascript&quot;&gt;<br />&lt;!--<br /><br />function&nbsp;isEnglish(name)&nbsp;//英文值检测<br />{<br />if(name.length&nbsp;==&nbsp;0)<br />return&nbsp;false;<br />for(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;name.length;&nbsp;i++)&nbsp;{<br />if(name.charCodeAt(i)&nbsp;&gt;&nbsp;128)<br />return&nbsp;false;<br />}<br />return&nbsp;true;<br />}<br /><br />function&nbsp;isChinese(name)&nbsp;//中文值检测<br />{<br />if(name.length&nbsp;==&nbsp;0)<br />return&nbsp;false;<br />for(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;name.length;&nbsp;i++)&nbsp;{<br />if(name.charCodeAt(i)&nbsp;&gt;&nbsp;128)<br />return&nbsp;true;<br />}<br />return&nbsp;false;<br />}<br /><br />function&nbsp;isMail(name)&nbsp;//&nbsp;E-mail值检测<br />{<br />if(!&nbsp;isEnglish(name))<br />return&nbsp;false;<br />i&nbsp;=&nbsp;name.indexOf(&quot;@&quot;);<br />j&nbsp;=&nbsp;name.lastIndexOf(&quot;@&quot;);<br />if(i&nbsp;==&nbsp;-1)<br />return&nbsp;false;<br />if(i&nbsp;!=&nbsp;j)<br />return&nbsp;false;<br />if(i&nbsp;==&nbsp;name.length)<br />return&nbsp;false;<br />return&nbsp;true;<br />}<br /><br />function&nbsp;isNumber(name)&nbsp;//数值检测<br />{<br />if(name.length&nbsp;==&nbsp;0)<br />return&nbsp;false;<br />for(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;name.length;&nbsp;i++)&nbsp;{<br />if(name.charAt(i)&nbsp;&lt;&nbsp;&quot;0&quot;&nbsp;||&nbsp;name.charAt(i)&nbsp;&gt;&nbsp;&quot;9&quot;)<br />return&nbsp;false;<br />}<br />return&nbsp;true;<br />}<br /><br />function&nbsp;CheckForm()<br />{<br />if(!&nbsp;isMail(form.Email.value))&nbsp;{<br />alert(&quot;您的电子邮件不合法!&quot;);<br />form.Email.focus();<br />return&nbsp;false;<br />}<br />if(!&nbsp;isEnglish(form.name.value))&nbsp;{<br />alert(&quot;英文名不合法!&quot;);<br />form.name.focus();<br />return&nbsp;false;<br />}<br />if(!&nbsp;isChinese(form.cnname.value))&nbsp;{<br />alert(&quot;中文名不合法!&quot;);<br />form.cnname.focus();<br />return&nbsp;false;<br />}<br />if(!&nbsp;isNumber(form.PublicZipCode.value))&nbsp;{<br />alert(&quot;邮政编码不合法!&quot;);<br />form.PublicZipCode.focus();<br />return&nbsp;false;<br />}<br />return&nbsp;true;<br />}<br />//--&gt;<br />&lt;/SCRIPT&gt;<br /><br />2.6&nbsp;限定表单项不能输入的字符<br /><br />&lt;script&nbsp;language=&quot;javascript&quot;&gt;<br />&lt;!--<br /><br />function&nbsp;contain(str,charset)//&nbsp;字符串包含测试函数<br />{<br />var&nbsp;i;<br />for(i=0;i&lt;charset.length;i++)<br />if(str.indexOf(charset.charAt(i))&gt;=0)<br />return&nbsp;true;<br />return&nbsp;false;<br />}<br /><br />function&nbsp;CheckForm()<br />{<br />if&nbsp;((contain(document.form.NAME.value,&nbsp;&quot;%\(\)&gt;&lt;&quot;))&nbsp;||&nbsp;(contain(document.form.MESSAGE.value,&nbsp;&quot;%\(\)&gt;&lt;&quot;)))<br />{<br />alert(&quot;输入了非法字符&quot;);<br />document.form.NAME.focus();<br />return&nbsp;false;<br />}<br />return&nbsp;true;<br />}<br />//--&gt;<br />&lt;/script&gt;&nbsp;

发表评论

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

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据