58 Classic JS Code

Source: Internet
Author: User
Tags date format define exit error handling flush header window
58 Classic JS Code collection, I hope to help you.

1. oncontextmenu= "Window.event.returnvalue=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= "JavaScript" ><!--
if (window = top) Top.location.href = "frames.htm"; Frames.htm for frames page
--></script>

9. Prevent a person from being frame
<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.offsetparent
T=t+a.offsettop
L=l+a.offsetleft
Wend
MsgBox "Top=" &T&CHR & "left=" &l,64, "get position of control"
End Function
--></script>

14. Cursor is stopped at the end of 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. Determining the origin of the previous page
Asp:
Request.ServerVariables ("Http_referer")

Javascript:
Document.referrer

16. Minimize, maximize, close windows
<object id=hh1 classid= "Clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" >
<param name= "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

17.
<%
Define some constants for database connections
Const adopenforwardonly = 0 cursors Only navigate forward records, do 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, additions or deletions are not reflected in the recordset. Supports moving forward or backward

Const adlockreadonly = 1 lock type, default, read only, can't make any changes
Const adlockpessimistic = 2 Lock records immediately when editing, the safest way
Const adLockOptimistic = 3 The recordset is locked only when the Update method is invoked, 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= "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 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=javascript>
function cc (DD,DADD)
{
You can add error handling
var a = new Date (DD)
A = A.valueof ()
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.value
Next
End Function
</script><BODY>
<input name= "Radio1" type= "Radio" value= "style" Checked>style
<input name= "Radio1" type= "Radio" value= "barcode" >barcode
<input type= "button" value= "Check" onclick= "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>value</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.
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 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 onkeydown= "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=javascript>
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 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 (" 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

30. No cache locally, automatic refresh every time
Response.expires=0
Response.AddHeader "Pragma", "No-cache"
Response.AddHeader "Cache-control", "private"

31. Modify contenttype and download GIF format
<%
function dl (f,n)
On Error Resume Next

Set S=createobject ("ADODB.stream")
S.mode=3
S.type=1
S.open
S.loadfromfile (Server.MapPath (f))
If Err.number>0 Then
Response.Write Err.Number & ":" & Err.Description
Else
Response.contenttype= "Application/x-gzip"
Response.AddHeader "Content-disposition:", "attachment; Filename= "& N
Response.BinaryWrite (S.read (s.size))
End If
End Function

Call DL ("012922501.gif", "T1.gif")
%>

32. Screen function Key Shift,alt,ctrl
<script>
function Look () {
if (Event.shiftkey)
Alert ("Do not press SHIFT key!";//Can be replaced with ALT CTRL
}
Document.onkeydown=look;
</script>

33. How do I make a form without bump and feel?
<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 "></textarea>

34.<div><span>&<layer> the difference?
<div> (division) is used to define a large section of the page elements, resulting in a career change
<span> to define elements within the same line, the only difference with <div> is not to create a career change
<layer> is the NS tag, IE does not support, the equivalent of <div>

35. Make pop-up windows always on top:
<body onblur= "This.focus ();" >

36. Do not scroll bar
Let the vertical bar not:
<body style= ' Overflow:-scroll;overflow-y:hidden ' >
</body>
Let the cross bar not:
<body style= ' Overflow:-scroll;overflow-x:hidden ' >
</body>
Two of them removed? It's even simpler.
<body scroll= "No" >
</body>

37. How to remove the picture link clicked, the dotted line around the picture?
<a href= "#" onfocus= "This.blur ()" ></a>

38. E-mail processing submitting form
<form name= "Form1" method= "Post" action= "mailto:****@***.com" enctype= "Text/plain" >
<input type=submit>
</form>

39. How do I write in the code that refreshes the parent window in the Open child window?
Window.opener.location.reload ()

40. How to set the size of the open page
<body onload= "Top.resizeto (300,200);" >
The location where the page is opened <body onload= "Top.moveby (300,200);" >

41. How to add a background picture that is not full on the page, pull the page when the background image does not move
<style>
Body
{Background-image:url (logo.gif); background-repeat:no-repeat;

Background-position:center;background-attachment:fixed}
</style>

42. Script never Goes wrong
<script language= "JavaScript" >
<!--Hide
function Killerrors () {
return true;
}
Window.onerror = killerrors;
-->
</SCRIPT>

43. Page entry and exit effects
Enter page <meta http-equiv= "Page-enter" content= "Revealtrans (duration=x, transition=y)" >
Launch page <meta http-equiv= "Page-exit" content= "Revealtrans (duration=x, transition=y)" >
This is some special effects when the page is loaded and paged out. Duration represents the duration, in seconds, of the effect. Transition said the

What kind of effect, the value is 1-23:
0 Rectangle Shrink
1 Rectangle Enlargement
2 round Shrink
3 Circular Enlargement
4 down to top refresh
5 Top to bottom refresh
6 Left to right refresh
7 Right to left flush
8 Vertical Blinds
9 Horizontal Blinds
10 Dislocation Horizontal Blinds
11 Misplaced Vertical Blinds
12 Point spread
13 or so to the middle of the refresh
14 Middle to left flush
15 Middle to bottom
16 up and down to the middle.
17 right down to top left
18 top right to bottom left
19 top left to bottom right
20 left down to top right
21 Cross Bar
22 Vertical Bar
23 or more of 22 randomly selected one

44. Jump within a specified time
<meta http-equiv=v= "REFRESH" content= "5; Url=http://www.51js.com ">

45. Whether the Web page has been retrieved
<meta name= "content=" Property value >
There are some of the following property values:
The property value is "All": The file will be retrieved and the link on the page can be queried;
The property value is "None": The file is not retrieved and the link on the page is not queried;
The property value is "index": The file will be retrieved;
Property value is "Follow": a link on the query page;
The property value is "Noindex": The file is not retrieved but can be queried for links;
The property value is "nofollow": The file is not retrieved, but the link on the page can be queried.

46. Transform the Web mouse cursor
<body style= "Cursor:url (http://203.73.125.205/~liangmi2/farmfrog01.cur')" >


47. How to change the color of the scroll bar, only ie5.5 version of the above can support.
This is the use of CSS language, in the time explained, it and my browser version has a certain relationship.
Scrollbar-arrow-color: The color of the top triangle arrow on the upper and lower buttons.
Scrollbar-base-color: The basic color of the scroll bar.
Scrollbar-dark-shadow-color: The color of the strong shadow of the solid scroll bar
Scrollbar-face-color: The color of the protruding part of the solid scroll bar
Scrollbar-highlight-color: The color of the blank part of the scroll bar
Scrollbar-shadow-color the color of the shadow of a stereo scroll bar.
Scrollbar-track-color: #99CC33;
Scrollbar-3dlight-color: #A8CBF1;
The code is as follows:
<style>
<!--
Body {
Scrollbar-face-color: #99CC33//(color of the protruding part of a solid scroll bar)
Scrollbar-highlight-color: #A8CBF1//(Color of the blank part of the scroll bar)
Scrollbar-shadow-color: #A8CBF1//(Color of the shadow of a solid scroll bar)
Scrollbar-arrow-color: #FF9966//(Color of triangle arrows on up and down buttons)
Scrollbar-base-color: #A8CBF1; (the basic color of the scroll bar)
Scrollbar-darkshadow-color: #A8CBF1; (Solid scroll bar strong shadow color)
Scrollbar-track-color: #99CC33;
Scrollbar-3dlight-color: #A8CBF1;
}
-->
</style>

48. How to shake the picture how to do.
<script language=javascript1.2>
<!--
var rector=2
var stopit=0
var a=1
var count=0
function init (which) {
Stopit=0
Shake=which
Shake.style.left=0
Shake.style.top=0
}
function Rattleimage () {
if ((!document.all&&!document.getelementbyid) stopit==1count==100)
Return
count++
if (a==1) {
Shake.style.top=parseint (shake.style.top) +rector
}
else if (a==2) {
Shake.style.left=parseint (Shake.style.left) +rector
}
else if (a==3) {
Shake.style.top=parseint (shake.style.top)-rector
}
else{
Shake.style.left=parseint (Shake.style.left)-rector
}
if (a<4)
a++
Else
A=1
SetTimeout ("Rattleimage ()", 50)
}
function Stoprattle (which) {
Stopit=1
Count=0
Which.style.left=0
Which.style.top=0
}
-->
</SCRIPT>
<style>.shakeimage {position:relative}
</style>

49. Open the window is maximized
<script language= "JavaScript" >
<!--Begin
Self.moveto (0,0)
Self.resizeto (Screen.availwidth,screen.availheight)
End-->
</script>

50. Thin Line Divider

51. The format for adding annotations is:   
〈!-[Annotation Content ... ]--〉

52.ie5.0 Part of the shortcut key:
A: Turn on find function: ctrl+f
Close browser window: ctrl+w
Open the Address bar drop-down list box: F4
Refresh: F5
Save the current Web page to your Favorites list: Ctrl+d
Open a copy of the current IE window: CTRL + N
Stop downloading the current page: ESC
The cursor moves quickly to the beginning of the page: Home
The cursor moves quickly to the end of the page:
Open a new Address type window: Ctrl+o
Open Favorites: Ctrl+i
Open History folder: Ctrl+h
Open the default home page for browser settings: Alt+home

53. Add to Favorites:
〈a href= "javascript:window.external.addFavorite (' http://link ', ' description ');" Add to Favorites 〈/a〉

54. Set as homepage:
〈a href=# onclick=this.style.behavior= ' url (#default #homepage) '; this.sethomepage (' http://link '); Set as homepage 〈/a〉

55. Expand the height of the IFRAME according to the content
<table><tr>
<TD id= "Mainview" >
<iframe src= "http://192.168.0.44/announce.asp?boardid=25"; Width= "100%" height= "100%" name= "main" scrolling= "no" border= "0" frameborder= "0" >
Here is the inner frame, if not see please upgrade your IE. </iframe></td>
</tr></table>
<script language= "JavaScript" for= "main" event= "onload" >
mainview.height=main.document.body.scrollheight+10;
</script>

56. Pop-up window automatically adapts to the size of the picture Code!
<script>
Str1=window.open (' Javascript:document.write ("<body style=margin:0></script>

57. Absolute and browser borders seamless Web page effect
<body bgcolor=menu style= "Border:none" scroll=no>

58. Show how long the construction station JS code
<script type= "Text/javascript" >
var urodz= new Date ("4/26/2004");
var s= "xx website since April 04 has been built station operation";
var now = new Date ();
var ile = Now.gettime ()-urodz.gettime ();
var dni = Math.floor (ile/(1000 * 60 * 60 * 24));
document.write ("" "+s+dni +" Day ")
</script>



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.