58 items-classic JS Code favorites

Source: Internet
Author: User
Tags servervariables

1.Oncontextmenu = "window. event. returnvalue = false" will completely block the right mouse button
<Table border oncontextmenu = return (false)> <TD> NO </table>

2.<Body onselectstart = "Return false"> cancel selection and prevent Replication

3.Onpaste = "Return false" Do not paste

4.Oncopy = "Return false;" oncut = "Return false;" Prevent Replication

5.<LINK rel = "shortcut icon" href = "favicon. ICO"> replace IE with your own icon in front of the address bar.

6.<LINK rel = "bookmark" href = "favicon. ICO"> you can display your icons in favorites.

7.<Input style = "ime-mode: Disabled"> disable the input method.

8. Always carry the framework
<Script language = "JavaScript"> <! --
If (window = Top) top. Location. href = "frames.htm"; // frames.htm is the frame webpage.
// --> </SCRIPT>

9. Prevent Frame
<Script language = JavaScript> <! --
If (top. location! = Self. Location) top. Location = self. location;
// --> </SCRIPT>

10.<NoScript> <IFRAME src = *. html> </iframe> </NoScript> webpages cannot be saved

11.<Input type = button value = view webpageSource code
Onclick = "window. Location = view-source: + http://www.csdn.net/'">

12. How to use ASP to check whether the visitor has used an agent?
<% If request. servervariables ("http_x_forwarded_for") <> "then
Response. Write "<font color = # ff0000> you have passed the proxy server ,"&_
"The real IP address is" & request. servervariables ("http_x_forwarded_for ")
End if
%>

13. Obtain 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 (13) & "Left =" & L, 64, "Get control position"
End Function
--> </SCRIPT>

14. The cursor stops at the end of the text box.
<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 source of the previous page
ASP:
Request. servervariables ("http_referer ")

Javascript:
Document. referrer

16. Minimize, maximize, and close the window
<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 = minimized onclick = hh1.click ()>
<Input type = button value = maximized onclick = hh2.click ()>
<Input type = button value = Disable onclick = hh3.click ()>
This example applies to IE

17.
<%
Define some constants for database connection
Const adopenforwardonly = 0 cursor only forward browsing records, does not support paging, recordset, bookmark
Const adopenkeyset = 1 key set cursor. changes made by other users to the record are reflected in the record set, but other users add or delete records are not reflected in the record set. Supports paging, recordset, and bookmark
Const adopendynamic = 2: the most dynamic cursor function, but the most resource consumption. The added or deleted records modified by the user on the record description will be reflected in the record set. Supports full-featured browsing (access is not supported ).
Const adopenstatic = 3 static cursor, which is only a snapshot of the data. The changes you make to the record, adding or deleting records, will not be reflected in the record set. Supports moving forward or backward

Const adlockreadonly = 1 lock type, default, read-only, cannot be modified
Const adlockpessimistic = 2 lock the record immediately when editing, the safest way
Const adlockoptimistic = 3 the record set is locked only when the update method is called. Other operations before this can still change, insert, and delete the current record.
Const adlockbatchoptimistic = 4 records are not locked when being edited, but changes, inserts, and deletes are completed in batch mode.

Const ad1_text = & h0001
Const adcmdtable = & h0002
%>

18. The webpage will not be cached
Htm webpage
<Meta HTTP-EQUIV = "Pragma" content = "no-Cache">
<Meta HTTP-EQUIV = "cache-control" content = "no-cache, must-revalidate">
<Meta HTTP-EQUIV = "expires" content = "wed, 26 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 webpage
Header ("expires: Mon, 26 Jul 1997 05:00:00 GMT ");
Header ("cache-control: No-cache, must-revalidate ");
Header ("Pragma: No-Cache ");


19. check whether a string is composed of digits.

<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 can I determine whether it is a character?
If (/[^ \ x00-\ xFF]/g. test (s) Alert ("containing Chinese characters ");
Else alert ("All characters ");

22. Number of lines of textarea adaptive text
<Textarea rows = 1 name = S1 Cols = 27 onpropertychange = "This. style. posheight = This. scrollheight">
</Textarea>

23. The date minus the number of days equals to the second date
<Script language = JavaScript>
Function CC (DD, dadd)
{
// Add error handling.
VaR A = new date (dd)
A = A. valueof ()
A = A-dadd * 24x60*60*1000
A = new date ()
Alert (A. getfullyear () + "year" + (A. getmonth () + 1) + "month" + A. getdate () + "day ")
}
CC ("12/23/2002", 2)
</SCRIPT>

24. Which radio is selected
<HTML> <script language = "VBScript">
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>

25. Obtain the request. servervariables ("") set of the URL on this page.
Response. Write "<Table border = 1> <! -- Table header --> <tr> <TD> <B> variables </B> </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.
Local IP address <% = 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 %>
Path of this file <% = server. mappath (request. servervariables ("script_name") %>
Server CPU count <% = request. servervariables ("number_of_processors") %>
Server interpreter engine <% = scriptengine & "/" & scriptenginemajorversion & "." & scriptengineminorversion & "." & scriptenginebuildversion %>
Server Operating System <% = request. servervariables ("OS") %>

27. Press enter to move the cursor to the next input box.
<Input onkeydown = "If (event. keycode = 13) event. keycode = 9">

28. Check the link speed of a Website:
Take the followingCodeAdd 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 ("

")
for (VAR I = 1; I document. write (" = " ="
")
document. write (" ")
}< br> 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 ++
}< br> function run () {for (VAR I = 1; I Run ()

29. Various styles of cursor
Auto: Standard cursor
Default: Standard arrow
Hand: Hand-shaped cursor
Wait: waiting for the cursor
Text: I-shaped cursor
Vertical-text: horizontal I-shaped cursor
No-drop: Do not drag the cursor
Not-allowed: Invalid cursor
Help :? Help cursor
All-scroll: triangle direction indicator
Move: Move mark
Crosshair: Cross logo
E-resize
N-resize
NW-resize
W-resize
S-resize
Se-resize
Sw-resize

30. No local cache, automatically refresh each time
Response. expires = 0
Response. addheader "Pragma", "No-Cache"
Response. addheader "cache-control", "private"

31. Modify contenttype and download GIF and other formats
<%
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. Block function keys shift, ALT, CTRL
<SCRIPT>
Function look (){
If (event. shiftkey)
Alert ("do not press shift! "; // You can change it to alt CTRL
}
Document. onkeydown = look;
</SCRIPT>

33. How to Make the form feel free of attention?
<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. What are the differences between <div> <span> & <layer>?
<Div> (Division) is used to define the page elements of a large segment, and a line is generated.
<Span> is used to define elements in the same row. The only difference between <div> and <div> is that no transpose is generated.
<Layer> is the NS tag, which is not supported by IE, which is equivalent to <div>

35. Make the pop-up window always on the top:
<Body onblur = "This. Focus ();">

36. Do not scroll bar
Make the vertical bar not:
<Body style = 'overflow:-scroll; overflow-Y: Den den '>
</Body>
Make the horizontal bar unavailable:
<Body style = 'overflow:-scroll; overflow-X: Den den '>
</Body>
Remove both of them? Simpler
<Body scroll = "no">
</Body>

37. How can I remove the dotted line around the image after clicking the image link?
<A href = "#" onfocus = "This. Blur ()"> </a>

38. email processing submission form
<Form name = "form1" method = "Post" Action = "mailto: ***** @ *****. com" enctype = "text/plain">
<Input type = submit>
</Form>

39. How to refresh the code of the parent window in the opened Child Window?
Window. opener. Location. Reload ()

40. How to set the page size
<Body onload = "Top. resizeTo (300,200);">
<Body onload = "Top. moveBy (300,200);">

41. How to add a background image that is not full? The background image does not move when pulling the page
<Style>
Body
{Background-image: url(logo.gif); background-repeat: No-Repeat;

Background-position: center; Background-Attachment: Fixed}
</Style>

42. Script never fails
<Script language = "JavaScript">
<! -- Hide
Function killerrors (){
Return true;
}
Window. onerror = killerrors;
// -->
</SCRIPT>

43. Special Effects for entering and exiting the page
Go to the <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 of page loading and calling. Duration indicates the duration of the special effect, in seconds. Transition indicates

Which special effect is used? The value ranges from 1 to 23:
0 rectangular narrowing
1. rectangular enlargement
2 rounded down
3. Circular Expansion
4. Refresh from bottom to top
Refresh from top to bottom
6-left-right refresh
7. right-to-left refresh
8 vertical blinds
9 horizontal blinds
10 misplaced horizontal blinds
11 misplaced vertical blinds
Spread
Refresh from around 13 to the center
14. Refresh from center to left
15.
16 up to the middle
17 bottom right to top left
18 top right to bottom left
19 upper left to lower right
20 bottom left to top right
21 horizontal bars
22 vertical bars
23 or more 22 types of random selection

44. Jump within the specified time
<Meta http-equiv = V = "refresh" content = "5; url = http://www.51js.com">

45. Whether the webpage is retrieved
<Meta name = "Robots" content = "attribute value">
The attribute values include the following:
Attribute Value: "All": the file will be retrieved and the link on the page can be queried;
Attribute Value: "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;
The property value is "follow": the link on the query page;
Attribute Value: "noindex": the file is not retrieved, but can be queried;
The property value is "nofollow": the file is not retrieved, but the link on the page can be queried.

46. Changing the mouse and cursor of a webpage
<Body style = "cursor: URL (http: // 203.73.125.205 /~ Liangmi2/farmfrow.1.cur ') ">

47. How to change the color of the scroll bar is supported only in ie5.5 or later versions.
This is the use of the CSS language. In this example, it has something to do with my browser version.
Scrollbar-arrow-color: The color of the upper and lower arrow of the upper and lower buttons.
Scrollbar-base-color: the Basic Color of the scroll bar.
Scrollbar-Dark-shadow-color: Color of the strong shadow of the three-dimensional scroll bar
Scrollbar-face-color: Color of the protruding part of the three-dimensional scroll bar
Scrollbar-Highlight-color: Color of the blank area of the scroll bar
Scrollbar-shadow-color specifies the color of the shadow of a three-dimensional 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 the three-dimensional scroll bar)
Scrollbar-Highlight-color: # a8cbf1; // (color of the blank area of the scroll bar)
Scrollbar-shadow-color: # a8cbf1; // (color of the shadow of the three-dimensional scroll bar)
Scrollbar-arrow-color: # ff9966; // (the color of the up and down arrow)
Scrollbar-base-color: # a8cbf1; // (Basic Color of the scroll bar)
Scrollbar-darkshadow-color: # a8cbf1; // (color of the strong shadow of the three-dimensional scroll bar)
Scrollbar-track-color: #99cc33;
Scrollbar-3dlight-color: # a8cbf1;
}
-->
</Style>

48. How do I perform image jitter.
<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 = 1 | COUNT = 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 a window to maximize
<Script language = "JavaScript">
<! -- Begin
Self. moveTo (0, 0)
Self. resizeTo (screen. availwidth, screen. availheight)
// End -->
</SCRIPT>

50. Fine line Separator
<HR noshade size = 0 color = # c0c0c0>

51. The format for adding annotations is:
<〈! -[Comment...] --> --〉

52. Some shortcut keys for ie5.0:
A: Turn on the search function: Ctrl + F
Close the browser window: Ctrl + W
Open the address bar drop-down list box: F4
New Refresh: F5
Save the current web page to the Favorites list: Ctrl + d
Open a copy of the current IE window: Ctrl + n
Stop downloading the current webpage: ESC
Move the cursor to the beginning of the webpage: Home
Move the cursor quickly to the end of the webpage: End
Open the new address. Enter Ctrl + O.
Open favorites: Ctrl + I
Open the history Folder: Ctrl + H
Open the default homepage set in the browser: 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 to homepage </a> 〉

55. Increase the IFRAME height based on 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 internal framework. If you cannot see it, upgrade your IE. </Iframe> </TD>
</Tr> </table>
<Script language = "JavaScript" for = "Main" event = "onLoad">
Mainview.heightdomainmain.doc ument. Body. scrollheight + 10;
</SCRIPT>

56. The pop-up window automatically adapts to the image size code!
<SCRIPT>
Str1 = Window. open ('javascript: document. write ("<body style = margin: 0> </SCRIPT>

57. Completely seamless web page effect with browser border
<Body bgcolor = menu style = "border: none" scroll = NO>

58. shows the JS Code for how long the website is built

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.