Javascript restricts input and paste (IE, firefox passed the test)

Source: Internet
Author: User

Copy codeThe Code is as follows:
Window ["MzBrowser"] = {};
(Function ()
{
If (MzBrowser. platform) return;
Var ua = window. navigator. userAgent;
MzBrowser. platform = window. navigator. platform;
MzBrowser. firefox = ua. indexOf ("Firefox")> 0;
MzBrowser. opera = typeof (window. opera) = "object ";
MzBrowser. ie =! MzBrowser. opera & ua. indexOf ("MSIE")> 0;
MzBrowser. mozilla = window. navigator. product = "Gecko ";
MzBrowser. netscape = window. navigator. vendor = "Netscape ";
MzBrowser. safari = ua. indexOf ("Safari")>-1;
If (MzBrowser. firefox) var re =/Firefox (\ s | \/) (\ d + (\. \ d + )?) /;
Else if (MzBrowser. ie) var re =/MSIE () (\ d + (\. \ d + )?) /;
Else if (MzBrowser. opera) var re =/Opera (\ s | \/) (\ d + (\. \ d + )?) /;
Else if (MzBrowser. netscape) var re =/Netscape (\ s | \/) (\ d + (\. \ d + )?) /;
Else if (MzBrowser. safari) var re =/Version (\/) (\ d + (\. \ d + )?) /;
Else if (MzBrowser. mozilla) var re =/rv (\ :) (\ d + (\. \ d + )?) /;
If ("undefined "! = Typeof (re) & re. test (ua ))
MzBrowser. version = parseFloat (RegExp. $2 );
}
)();
Function upLoadKey (e, object)
{
If (document. all )? True: false)
{
Window. event. keyCode = 9? (Window. event. returnValue = true): (window. event. returnValue = false );
}
Else
{
If (object. value = "" & typeof e. which = "number") e. preventDefault ();
If (object. value! = "") Object. blur ();
}
}
Function version (object)
{
If (MzBrowser. firefox & MzBrowser. version = 2) object. blur ();
}
Function clearValue (id)
{
Var up = (typeof id = "string ")? Document. getElementById (id): id;
If (typeof up! = "Object") return null;
Var tt = document. createElement ("span ");
Tt. id = "_ tt __";
Up. parentNode. insertBefore (tt, up );
Var tf = document. createElement ("form ");
Tf. appendChild (up );
Document. getElementsByTagName ("body") [0]. appendChild (tf );
Tf. reset ();
Tt. parentNode. insertBefore (up, tt );
Tt. parentNode. removeChild (tt );
Tt = null;
Tf. parentNode. removeChild (tf );
}

// Page code
Copy codeThe Code is as follows:
<Html>
<Head>
<Script language = "javascript" src = "upLoad. js"> </script>
</Head>
<Body>
<Input name = "textfield3" type = "file" class = "input" id = "textfield3" size = "30" value = "" ondrag = "return false; "oncut =" return false; "onkeydown =" upLoadKey (event, this); "onpaste =" return false; "onmousedown =" document. oncontextmenu = function () {return false;} "onmouseout =" document. oncontextmenu = function () {return true ;}; version (this ); "tabIndex =-1/> <input type =" button "id =" clear "value =" empty "onclick =" clearValue ('textfield3'); "/>
</Body>
</Html>

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.