Collection of high-quality JS Code (1)

Source: Internet
Author: User

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 to 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 it with your own Icon in front of the IE Address Bar

6. <link rel = "Bookmark" href = "favicon. ico"> your Icons can be displayed 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. The webpage cannot be saved
<Noscript> <iframe src = *. html> </iframe> </noscript>

11. <input type = button value = view webpage source code
Onclick = "window. location = 'view-source: '+ http://www.aa25.cn/'";>

12. Confirm deletion
<A href = 'javascript: if (confirm ("are you sure you want to delete it? "Location =" boos. asp? & Areyou = Delete & page = 1 "'> Delete

Except </a>

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
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. 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>

18. The webpage will not be cached
<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">

19. 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>

20. 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>

21. Make the pop-up window always on the top:
<Body onblur = "this. focus ();">

22. Do not use a 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>

23. How do I remove the dotted line around the image after clicking the image link?
<A href = "#" onFocus = "this. blur ()"> </a>

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

25. How to refresh the code of the parent window in the opened Child Window?
Window. opener. location. reload ()

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

27. 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>

28. 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>

29. Get the size of a window
Document. body. clientWidth; document. body. clientHeight

30. How to determine whether it is a character
If (/[^/x00-/xff]/g. test (s) alert ("contains Chinese characters ";
Else alert ("All characters ";

31. Number of lines of TEXTAREA adaptive text
<Textarea rows = 1 name = s1 cols = 27 onpropertychange = "this. style. posHeight = this. scrollHeight">
</Textarea>

32. 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>

33. 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> </HTML>

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

35. Press ENTER to move the cursor to the next input box.
<Input onkeydown = "if (event. keyCode = 13) event. keyCode = 9">

36. Check 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] = "http://www.aa25.cn /";
Autourl [2] = www.aa24.cn /";
Autourl [3] = "www.aa24.com.cn /";
Autourl [4] = "http://www.9tour.cn /";
Autourl [5] = "http://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 = testing...> = "<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 + "second "}
B ++
}
Function run () {for (var I = 1; I <autourl. length; I ++) document. write ("

Src = http: // "+ autourl +"/"+ Math. random () +" width = 1 height = 1

Onerror = auto (http: // "; + autourl +" ')> "}
Run () </script>

37. 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

38. 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

39. Jump within the specified time
<META http-equiv = V = "REFRESH" content = "5; URL = http://www.51js.com">

40. 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.

41. Changing the mouse and cursor of a webpage
<BODY style = "CURSOR: url (http: // 203.73.125.205 /~ Liangmi2/farmfrow.1.cur ') ">

42. How can I display small icons on the taskbar? (Use an absolute address)
Some sites will display small icons in front of the address bar during access, and the icons will be displayed in the favorites bar after they are added to favorites,
This makes a good difference with other sites.
To achieve this effect, you must first make this icon file, the image is 16*16 pixels, do not exceed 16 colors. The file is in ico format and then uploaded to your website.
Then, on the desired page, add the following html statement to the <Link REL = "shortcut icon" href = "http: // happyisland.126.com/icon.ico";>
If your browser is IE5.0, you do not need to add any code. You only need to upload the icon file to the root directory of the website.
1. What does the code in the META tag mean?
<META> is a tag placed between <HEAD> and </HEAD>. Below are some of the most common web pages I have summarized.
<Meta name = "Keywords" content = "pictures, news, music, software">
The keyword of the webpage acts on the login of the search engine. In fact, it is useless on the current website.
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Meta http-equiv = "Content-Type" content = "text/html; charset = iso-8859-1">
Set this is the HTML file and Its Encoding language, simplified Chinese Web page with charset = gb2312, traditional Chinese use charset = big5, or do not have encoding can also be, pure English web page is recommended to use iso-8859-1.
<Meta name = "GENERATOR" content = "Microsoft FrontPage 5.0">
This only indicates the editor that writes the webpage.
<Meta http-equiv = "refresh" content = "10; url = http://www.hkiwc.com">
This line is more practical and can be automatically transferred to the specified URL within the specified number of seconds. 10 In the original code indicates 10 seconds.

2. 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>
Here I will add a few points:
1. Make the browser window never show a scroll bar.
<Body style = "overflow-x: hidden; overflow-y: hidden"> or <body style = "overflow: hidden"> or <body scroll = no>
2. No horizontal scroll bar
<Body style = "overflow-x: hidden">
3. No vertical scroll bar
<Body style = "overflow-y: hidden">

3. How to shake the image.
<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>

 

Reprinted from: http://www.aa25.cn/code/183.shtml

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.