function Nocontextmenu ()
{
if (document.all) {
Event.cancelbubble=true;
Event.returnvalue=false;
return false;
}
}
Or
<body oncontextmenu= "Nocontextmenu ()" >
<script language= "JavaScript" >
<!--
function Rclick ()
{
if (document.all) {
if (Event.button = = 2) {
Event.returnvalue=false;
}
}
}
-->
</script>
1.3 Mask CTRL + N, SHIFT+F10, F5 refresh, backspace key
<script language= "JavaScript" >
<!--
Screen the right mouse button, CTRL + N, SHIFT+F10, F5 refresh, backspace key
function Window.onhelp () {return false}//Shield F1 Help
function KeyDown () {
if ((Window.event.altKey) &&
((window.event.keycode==37) | |//Shielding ALT + Direction key ←
(window.event.keycode==39))) {//Shielding ALT + Direction key →
Alert ("You are not allowed to use ALT + arrow keys forward or back page!") ");
Event.returnvalue=false;
}
* Note: This is not really shielding ALT + arrow keys,
Because ALT + ARROW keys pop-up warning box, hold down the ALT key,
With the mouse point off the warning box, this shielding method is invalid. Later if
There is a master who has really shielded the Alt key method, please inform. */
if ((Event.keycode = 8) &&
(Event.srcElement.type!= "text" &&
Event.srcElement.type!= "textarea" &&
Event.srcElement.type!= "password") | | Mask BACKSPACE Delete key
(Event.keycode ==116) | | Mask F5 Refresh Key
(Event.ctrlkey && event.keycode==82)) {//ctrl + R
event.keycode=0;
Event.returnvalue=false;
}
if ((Event.ctrlkey) && (event.keycode==78))//Shield CTRL + N
Event.returnvalue=false;
if ((Event.shiftkey) && (event.keycode==121))//Shielding SHIFT+F10
Event.returnvalue=false;
if (Window.event.srcElement.tagName = "A" && Window.event.shiftKey)
Window.event.returnvalue = false; Screen shift plus left mouse button new page open
if ((Window.event.altKey) && (window.event.keycode==115)) {//Shield ALT+F4
Window.showmodelessdialog ("About
: blank "," "," dialogwidth:1px;dialogheight:1px ");
return false;}
}
/* can also be used to screen all the menu of IE window.open
The first method:
window.open ("Your. htm", "", "toolbar=no,location=no,directories= no,menubar=no,scrollbars=no,resizable=yes,status= No,top=0,left=0 ")
The second way is to open a Full-screen page:
window.open ("Your. asp", "", "Fullscreen=yes")
*/
-->
</script>
1.4 Screen browser in the upper right corner, minimize, maximize, close key
<script language=javascript>
function Window.onbeforeunload ()
{
if (event.clientx>document.body.clientwidth&&event.clienty<0| | Event.altkey)
{
Window.event.returnvalue = "";
}
}
</script>
<script language= "JavaScript" >
<!--
function Checkform ()
{
if (Document.form.name.value.length = = 0) {
Alert ("Please enter your name!");
Document.form.name.focus ();
return false;
}
return true;
}
-->
</script>
2.2 Compare the values of two table items
<script language= "JavaScript" >
<!--
function Checkform ()
if (Document.form.PWD.value!= document.form.PWD_Again.value) {
Alert ("The password you entered two times is different!") Please re-enter. ");
Document. ADDUser.PWD.focus ();
return false;
}
return true;
}
-->
</script>
2.3 Form items can only be numbers and "_" for phone/bank account verification, can be extended to domain name registration, etc.
<script language= "JavaScript" >
<!--
function Isnumber (String)
{
var letters = "1234567890-"; You can add your own input value
var i;
var C;
if (String.charat (0) = = '-')
return false;
if (String.charat (string.length-1) = = '-')
return false;
for (i = 0; i < string.length i + +)
{
c = String.charat (i);
if (Letters.indexof (c) < 0)
return false;
}
return true;
}
function Checkform ()
{
if (! Isnumber (Document.form.TEL.value)) {
Alert ("Your phone number is not legal!") ");
Document.form.TEL.focus ();
return false;
}
return true;
}
-->
</script>
2.4 Table Single input value/length limit
<script language= "JavaScript" >
<!--
function Checkform ()
{
if (Document.form.count.value > | | Document.form.count.value < 1)
{
Alert ("The input value cannot be less than 0 or greater than 100!");
Document.form.count.focus ();
return false;
}
if (document.form.message.value.length<10)
{
Alert ("Input text is less than 10!");
Document.form.MESSAGE.focus ();
return false;
}
return true;
}
-->
</script>
function Isenglish (name)//English value detection
{
if (name.length = 0)
return false;
for (i = 0; i < name.length; i++) {
if (Name.charcodeat (i) > 128)
return false;
}
return true;
}
function Ischinese (name)//Chinese value detection
{
if (name.length = 0)
return false;
for (i = 0; i < name.length; i++) {
if (Name.charcodeat (i) > 128)
return true;
}
return false;
}
function IsMail (name)/e-mail value detection
{
if (! Isenglish (name))
return false;
i = Name.indexof ("@");
j = Name.lastindexof ("@");
if (i = = 1)
return false;
if (i!= j)
return false;
if (i = = name.length)
return false;
return true;
}
function Isnumber (name)//numeric detection
{
if (name.length = 0)
return false;
for (i = 0; i < name.length; i++) {
if (Name.charat (i) < "0" | | name.charat (i) > "9")
return false;
}
return true;
}
function Checkform ()
{
if (! IsMail (Form). Email.value)) {
Alert ("Your email is illegal!) ");
Form. Email.focus ();
return false;
}
if (! isenglish (Form.name.value)) {
Alert ("The English name is illegal!") ");
Form.name.focus ();
return false;
}
if (! Ischinese (Form.cnname.value)) {
Alert ("Chinese name is illegal!") ");
Form.cnname.focus ();
return false;
}
if (! isnumber (Form). Publiczipcode.value)) {
Alert ("ZIP code not valid!) ");
Form. Publiczipcode.focus ();
return false;
}
return true;
}
-->
</SCRIPT>
2.6 Qualifying A form item cannot enter characters
<script language= "JavaScript" >
<!--
function contain (Str,charset)//string contains test functions
{
var i;
for (i=0;i<charset.length;i++)
if (Str.indexof (Charset.charat (i)) >=0)
return true;
return false;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.