Collection of fine Code

Source: Internet
Author: User
Tags add date object end error handling header net window

Collection of fine Code

1. oncontextmenu= "window.event.return& #118alue =false" will completely screen the right mouse button
<table border Oncontextmenu=return (false) ><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 with the frame
<script language= "& #106avascript" ><!--
if (window = top) Top.location.href = "frames.htm"; file& #58//frames.htm for frames page
--></script>
9. Prevent a person from being frame
<script language=& #106avascript ><!--
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 & #118alue = View Web page source code
& #111nclick = "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
file& #58//& #106avascript
<script language= "& #106avascript" >
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>
file& #58//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.offsetparent
T=t+a.offsettop
L=l+a.offsetleft
Wend
MsgBox "Top=" &AMP;T&AMP;CHR & "left=" &l,64, "get position of control"
End Function
--></script>
14. Cursor is stopped at the end of text box text
<script language= "& #106avascript" >
function cc ()
{
var e = event.srcelement;
var r =e.createtextrange ();
R.movestart (' character ', e.& #118alue. length);
R.collapse (TRUE);
R.select ();
}
</script>
<input type=text name=text1 & #118alue = "123" >
15. Determining the origin of the previous page
Asp:
Request.ServerVariables ("Http_referer")
& #106avascript:
Document.referrer
16. Minimize, maximize, close windows
<object id=hh1 classid= "Clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" >
<param name= "Command" & #118alue = "Minimize" ></object>
<object id=hh2 classid= "Clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" >
<param name= "Command" & #118alue = "Maximize" ></object>
<object id=hh3 classid= "Clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" >
<param name= "Command" & #118alue = "Close" ></OBJECT>
<input Type=button & #118alue = minimize & #111nclick =hh1. Click () >
<input Type=button & #118alue = maximize & #111nclick =hh2. Click () >
<input Type=button & #118alue = Shut down & #111nclick =hh3. Click () >
This example applies to IE
17.
<%
' Define some constants for database connections
The Const adopenforwardonly = 0 ' cursor only browses the record forward, does not support paging, Recordset, BookMark
The Const adOpenKeyset = 1 ' keyset cursor, the changes that other users make to the record are reflected in the recordset, but additional users adding or deleting records are not reflected in the recordset. Support paging, Recordset, BookMark
The 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 cursors, just a snapshot of the data, changes that the user makes to the record, adding or deleting records are not reflected in the recordset. Supports moving forward or backward
Const adlockreadonly = 1 ' lock type, default, read-only, cannot make any changes
Const adlockpessimistic = 2 ' When editing immediately locks records, the safest way
Const adlockoptimistic = 3 ' The recordset is locked only when the Update method is called, while other previous operations can still make changes, inserts, and deletes to the current record.
Const adlockbatchoptimistic = 4 ' records are not locked while editing, and changes, inserts, and deletions are done in batch mode
Const adCmdText = &h0001
Const adCmdTable = &h0002
%>
18. Web pages are not cached
HTM Web page
<meta http-equiv= "Pragma" content= "No-cache" >
<meta http-equiv= "Cache-control" content= "No-cache, must-revalidate" >
<meta http-equiv= "Expires" content= "Wed Feb, 1997 08:21:57 GMT" >
or <meta http-equiv= "expires" content= "0" >
ASP Web page
Response.Expires =-1
Response.ExpiresAbsolute = Now ()-1
Response.CacheControl = "No-cache"
PHP Web page
Header ("Expires:mon, June June 1997 05:00:00 GMT");
Header ("Cache-control:no-cache, must-revalidate");
Header ("Pragma:no-cache");
19. Check whether a string of strings is all composed of numbers
<script language= "& #106avascript" ><!--
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 judge whether it is a character
if (/[^\x00-\xff]/g.test (s)) alert ("contains Chinese characters");
else alert ("All characters");
22.TEXTAREA the 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=& #106avascript >
function cc (DD,DADD)
{
file& #58//Can be added with error handling
var a = new Date (DD)
A = a.& #118alueOf ()
A = A-dadd * 24 * 60 * 60 * 1000
A = new Date (a)
Alert (a.getfullyear () + "year" + (A.getmonth () + 1) + "month" + a.getdate () + "Day")
}
CC ("12/23/2002", 2)
</script>
24. Which radio was chosen
function Checkme ()
For each OB in Radio1
If ob.checked then Window.alert ob.& #118alue
Next
End Function
</script><BODY>
<input name= "Radio1" type= "Radio" & #118alue = "Style" Checked>style
<input name= "Radio1" type= "Radio" & #118alue = "Barcode" >barcode
<input type= "button" & #118alue = "Check" & #111nclick = "Checkme ()" >
</BODY></HTML>
25. Get the Request.ServerVariables ("") collection of the URL on this page
Response.Write "<table border=1><!--TABLE Header--><tr><td><b>variables</b> </td><td><b>& #118alue </B></TD></TR> "
For each OB in Request.ServerVariables
Response.Write "<TR><TD>" &ob& "</TD><TD>" &request.servervariables (OB) & " </TD></TR> "
Next
Response.Write "</TABLE>"
26. This machine 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 Time <%=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 & #111nkeydown = "if (event.keycode==13) event.keycode=9" >
28. Detect the link speed of a website:
Add the following code to the <body> area:
<script language=& #106avascript >
Tim=1
SetInterval ("tim++", 100)
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 & #118alue = Test ......> =" <input type=text name=url "+i+" size =40> = "<input Type=button & #118alue =go & #111nclick =window.open (this.form.url" +i+ ". & #118alue) ><br/>" )
document.write ("<input type=submit & #118alue = Refresh ></form>")
}
Butt ()
function Auto (URL) {
document.forms[0]["url" +b].& #118alue =url
if (tim>200)

Else

b++
}
function run () {for (Var i=1;i<autourl.length;i++) document.write ("Run () </script>
29. Various styles of cursors
Auto: Standard cursor
Default: Standard arrow
Hand: hand-shaped cursor
Wait: Waiting for cursor
Text:i-shaped cursor
Vertical-text: Horizontal i-type cursor
No-drop: Non-drag cursor
Not-allowed: Invalid cursor
Help:? Helper cursors
All-scroll: Triangle directional Sign
Move: Moving the label
Crosshair: Cross Mark
E-resize
N-resize
Nw-resize
W-resize
S-resize
Se-resize
Sw-resize



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.