"Recommended" very good JavaScript script

Source: Internet
Author: User
Tags count delete key key return window domain name domain name registration to domain
javascript| Script 1 > Shielding function class

1.1 Screen Keyboard all keys
<script language= "JavaScript" >
<!--
function Document.onkeydown () {
Event.keycode = 0;
Event.returnvalue = false;
}
-->
</script>

1.2 Screen right mouse button

Add Oncontextmenu=self.event.returnvalue=false to the body tag.

Or

<script language= "JavaScript" >
<!--
function Document.oncontextmenu ()
{
return false;
}
-->
</script>

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>

or open the page with full screen

<script language= "JavaScript" >
<!--
window.open (www.32pic.com, "32pic", "fullscreen=3,height=100, width=400, Top=0, left=0, Toolbar=no, Menubar=no, Scrollbars=no, Resizable=no,location=no, Status=no ");
-->
</script>

Note: Add onbeforeunload= to the body tag "javascript : Return False (make window not close)

1.5 Shielding F5 Key

<script language= "JavaScript" >
<!--
function Document.onkeydown ()
{
if (event.keycode==116)
{
Event.keycode = 0;
Event.cancelbubble = true;
return false;
}
}
-->
</script>

1.6 Screen IE Back button

Use <a href= "javascript when you link" : Location.replace (URL) ">

1.7 Screen main Window scroll bar

Add style= "Overflow-y:hidden" to the body tag.

1.8 screen screen, constantly emptying the clipboard

Add it to the body tag.

1.9 Screen printing function of the website

<style>
@media Print {
* {Display:none}
}
</style>

1.10 Screen IE6.0 Save icon automatically appears on the picture

Method One:
<meta http-equiv= "Imagetoolbar" content= "no" >
Method Two:


1.11 All script in the screen page

<noscrript></noscript>

2 > form Submission Verification class


2.1 Form items cannot be empty

<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>

2.5 Chinese/English/digital/email address legality judgment

<script language= "JavaScript" >
<!--

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;
}

function Checkform ()
{
if ((Contain (Document.form.NAME.value,%\ (\) ><)) | | (Contain (Document.form.MESSAGE.value, "%\ (\) ><"))
{
Alert ("entered an illegal character");
Document.form.NAME.focus ();
return false;
}
return true;
}
-->
</script>

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.