Some of the little tricks of JavaScript

Source: Internet
Author: User
Tags error handling servervariables server port
1. oncontextmenu= "Window.event.returnvalue=false" will completely screen the right mouse button <table border Oncontextmenu=return (false) &GT;&LT;TD >no</table> Available for table

2. <body onselectstart= "return false" > deselect, prevent copying

3. onpaste= "return false" is not allowed to paste

4. oncopy= ' return false; ' oncut= ' return false; ' Prevent replication

5. <link rel= "shortcut icon" href= "Favicon.ico" > IE Address bar before replacing their own icons

6. <link rel= "Bookmark" href= "Favicon.ico" > can display your icon in a Favorites folder

7. <input style= "ime-mode:disabled" > Close IME

8. Always take the frame <script language= "JavaScript" ><!--if (window = top) Top.location.href = "frames.htm"; Frames.htm for frames page//--></script>

9. Prevent <script language=javascript><!--if (top.location!= self.location) top.location=self.location; --></script>

<noscript><iframe src=*.html></iframe></noscript> Web pages will not be saved as

<input type=button value= View Web page source code onclick= "window.location =/' view-source:/' +/' http://www.csdn.net//'" >

12. How to use the ASP means to check whether the visitor used the agent <% if Request.ServerVariables ("Http_x_forwarded_for") <> "Then Response.Write" <font color= #FF0000 > You have passed the proxy server, "& _" True IP is "&request.servervariables" ("http_x_forwarded_for") End If% >

13. Get the absolute position of the control//javascript <script language= "Javascript" > Function Getie (e) {var t=e.offsettop;  var l=e.offsetleft;  while (e=e.offsetparent) {t+=e.offsettop;  L+=e.offsetleft;  Alert ("top=" +t+ "/nleft=" +l); } </script>//vbscript <script language= "VBScript" ><!--function Getie () Dim t,l,a,b set A=document. ALL.IMG1 t=document.all.img1.offsettop L=document.all.img1.offsetleft while a.tagname<> "Body" set a = A.offsetPa Rent t=t+a.offsettop l=l+a.offsetleft wend MsgBox "Top=" &AMP;T&AMP;CHR (& "left=" &l,64, "get position of control" end Functio N--></script>

14. The cursor is at the end of the text box text <script language= "JavaScript" > Function cc () {var e = event.srcelement;  var r =e.createtextrange ();  R.movestart (/' character/', e.value.length);  R.collapse (TRUE);  R.select (); } </script> <input type=text name=text1 value= "123" onfocus= "CC ()" >

15. Determine the origin of the previous page asp:request.servervariables ("Http_referer") Java Script:document.referrer

16. Minimize, maximize, close windows <object id=hh1 classid= "clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" > <param "Command"  Value= "Minimize" ></object> <object id=hh2 classid= "Clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" > <param name= "Command" value= "maximize" ></object> <object id=hh3 classid= "CLSID: Adb880a6-d8ff-11cf-9377-00aa003b7a11 "> <param name=" Command "value=" Close "></OBJECT> <input type= Button value= Minimize onclick=hh1. Click () > <input Type=button value= maximize ONCLICK=HH2. Click () > <input type=button value= closes Onclick=hh3. Click () > This example applies to IE

<%/' Define some constants of the database connection const ADOPENFORWARDONLY = 0/' Cursors only navigate the record forward, do not support paging, Recordset, BookMark Const adopenkeyset = 1/' Key set Tour , the changes that other users make to the record will be reflected in the recordset, but other users adding or deleting records will not be reflected in the recordset. Supports paging, Recordset, BookMark Const adopendynamic = 2/' Dynamic cursors are the most powerful, but also the most expensive sources. User changes to the record, add or delete records will be reflected in the recordset.  Supports full feature browsing (not supported by Access). Const adOpenStatic = 3/' static cursor, just a snapshot of the data, user changes to the record said, add or delete records are not reflected in the recordset. Support forward or backward move const ADLOCKREADONLY = 1/' lock type, default, read only, cannot make any changes const adLockPessimistic = 2/' When editing immediately locks record, the safest way to const adlock optimistic = 3/' The Recordset is locked only when the Update method is called, while other previous operations can still make changes to the current record, insert, and delete the Const adlockbatchoptimistic = 4/' When editing the record is not locked and the change, Insert and delete are the const adCmdText = &h0001 Const adCmdTable = &h0002%> in batch mode

18. Web page will not be cached   HTM page   <meta http-equiv= "Pragma" content= "No-cache" >  <meta http-equiv= " Cache-control "content=" No-cache, must-revalidate ">  <meta http-equiv=" Expires "content=" Wed, Num FEB 1997 08:21:57 GMT ">  or <meta http-equiv=" expires "content=" 0 ">  ASP pages   Response.Expires = -1  Response.ExpiresAbsolute = Now ()-1  Response.CacheControl = "No-cache"   PHP Web page   Header ("Expires:mon, J UL 1997 05:00:00 GMT ");  header (" Cache-control:no-cache, must-revalidate ");  header (" Pragma:no-cache ");    How to make the form feel no bump.   <input type=text style= "border:1 solid #000000" >  or   <input type=text style= "Border-left:none ; Border-right:none; Border-top:none; Border-bottom:1 solid #000000 "></the difference between textarea>   <div><span>&<layer>.   <div> (division) is used to define a large section of the page elements, will produce a career change   <span> used to define the same line of elements, the only difference with the <div> is not to create a career change   < Layer> is the NS tag, IE does not support the equivalent of <div>   let pop-up windows always:  <body onblur= "This.focus ();" >   do not scroll bar?  let the vertical bar have no:  <body style=/' overflow:scroll;overflow-y:hidden/' >  </body >  Let the bars have no:  <body style=/' overflow:scroll;overflow-x:hidden/' >  </body>  two are removed. Simpler   <body scroll= "No" >  </body>   how to remove a picture link after clicking the dotted line around the picture.   <a href= "#" onfocus= "This.blur ()" ></a>   e-mail processing submission Form   <form name= "Form1" method= "Post" action= "mailto:****@***.com" enctype= "Text/plain" >  <input type =submit>  </form>   How to write in the code that refreshes the parent window in the Open child window.   Window.opener.location.reload ()    How to set the size of the open page   <body onload= "Top.resizeto (300,200);" >   How to add a background picture that is not full on the page, pull the page when the background image does not move  
19. Check whether a string of strings is composed entirely of numbers <script language= "Javascript" ><!--function Checknum (str) {return Str.match (//d/) ==null} Alert (Checknum ("1232142141")) Alert (Checknum ("123214214A1"))//--></script>

20. Get the size of a window document.body.clientwidth,document.body.clientheight

21. How to determine whether the character if (/[^/x00-/xff]/g.test (s)) alert ("contains Chinese characters"); else alert ("All characters");

TextArea number of adaptive lines of text < textarea Rows=1 name=s1 cols=27 onpropertychange= "This.style.posheight=this.scrollheight" > </textarea>

23. Date minus days equals second date <script language=javascript> function cc (DD,DADD) {//can be added error handling var a = new Date (dd) A = A.va Lueof () A = A-dadd * * 1000 a = new Date (a) alert (a.getfullyear () + "year" + (A.getmonth () + 1) + "month" + A.G Etdate () + "Day"} cc ("12/23/2002", 2) </script>

24. Choose which radio
26. Native Ip<%=request.servervariables ("REMOTE_ADDR")%> server name <%=request.servervariables ("SERVER_NAME")%>  Server Ip<%=request.servervariables ("LOCAL_ADDR")%> Server Port <%=request.servervariables ("SERVER_PORT")%> Server Time <%=now%> IIS version <%=request.servervariables "Server_software")%> script timeout <%=server.scripttimeout% > This file path <%=server.mappath (Request.ServerVariables ("Script_name")%> Server CPU number <%= Request.ServerVariables ("number_of_processors")%> Server Interpreter engine <%=scriptengine & "/" & ScriptEngineMajorVersion & "." &ScriptEngineMinorVersion& "." & scriptenginebuildversion%> Server operating system <%=request.servervariables ("OS")%>

The 27.ENTER key allows the cursor to move to the next input box <input onkeydown= "if (event.keycode==13) event.keycode=9" >

28. Detect the link speed of a website:  the following code into the <body> area:  <script language=javascript>  tim=1  SetInterval ("tim++")   b=1   var autourl=new Array ()   autourl[1]= "Www.njcatv.net"   autourl[2]= "javacool.3322.net"   autourl[3]= "www.sina.com.cn"   autourl[4]= "www.nuaa.edu.cn"   autourl[5]= "www.cctv.com"    function Butt () {  document.write ("<form name=autof>")   for ( var i=1;i<autourl.length;i++)   document.write ("<input type=text name=txt" +i+ "size=10 value= Test ......> =" <input type=text name=url "+i+" size=40> = "<input Type=button value=go onclick=window.open (this.form.url" +i+ " . Value) ><br> ")   document.write (" <input type=submit value= Refresh ></form> ")  }  Butt (   function Auto (URL) {  document.forms[0]["url" +b].value=url  if (tim>200)   {document.forms[0 ["TXT" +b].value= "link Timeout"}  else  {document.forms[0]["txt" +b].value= "time" +tim/10+ "seconds"}  B ++ }  function Run () {for (Var i=1;i<autourl.length;i++) document.write ("   

29. Various styles of CURSOR Auto: Standard cursor default: Standard arrow hand: Hand cursor wait: Waiting cursor text:i cursor Vertical-text: Horizontal i cursor No-drop: non-drag cursor not-al  lowed: Invalid cursor help:? Helper cursor All-scroll: Triangle Direction move: Moving label crosshair: Cross e-resize n-resize nw-resize w-resize Se-resize sw-resize
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.