70 simple and easy-to-use JS Codes

Source: Internet
Author: User

70Common JSCode

1. Move backward
<Input type = "button" value = "back"
Onclick = "history. Go (-1)">
<Input type = "button" value = "Forward"
Onclick = "history. Go (1); Return true;">

2. Return
<Form> <input type = "button" value = "back to previous step"
Onclick = "history. Back (-1)"> </form>

3. View Source Code
<Input type = "button" name = "View" value = "view source code" onclick = "window. Location =" view-source :"
+ Window. Location. href ">

4. Do not view source code
<Body oncontextmenu = "Return
False "> </body>

5. Refresh button 1
<Input type = "button" value = "Refresh button 1"
Onclick = "reloadbutton ()">
<SCRIPT> Function
Reloadbutton () {location. href = "i001.htm" ;}</SCRIPT>

Refresh button 2
<Input type = "button" value = "Refresh button 2"
Onclick = "history. Go (0)">

6. Home page buttons
<Input type = "button" value = "Homepage"
Onclick = "homebutton ()">
<SCRIPT> function homebutton () {location. href = http://www.winliuxq.com;} </SCRIPT>

7. A warning box is displayed.
<Input type = "button" value = "pop-up warning box"
Onclick = "alertbutton ()">
<SCRIPT> function alertbutton () {window. Alert ("coming soon! ") ;}</SCRIPT>

8. Status Bar Information
<Input type = "button" value = "status bar information"
Onclick = "statusbutton ()">
<SCRIPT> function statusbutton () {window. Status = "coming soon! ";}</SCRIPT>

9. Background Color Conversion
<Form> <input type = "button" value = "background color conversion"
Onclick = "bgbutton ()"> </form>
<SCRIPT> function bgbutton (){
If (document. bgcolor = '# 00ffff ')
{Document. bgcolor = '# ffff ';}
Else {document. bgcolor = '# 00ffff ';}
}
</SCRIPT>

10. open a new window
<Input type = "button" value = "open new window"
Onclick = "newwindow ()">
<SCRIPT> Function
Newwindow () {window. open ("c01.htm", "", "Height = 240, width = 340, status = No, location = No, toolbar = No, directories = No, menubar = No ");}

</SCRIPT>

11. Minimize windows
<Object ID = "min" type = "application/X-oleobject"
Classid = "CLSID: adb880a6-d8ff-11cf-9377-00aa003b7a11"> <Param
Name = "command"
Value = "minimize"> </Object> <button
Onclick = "Min. Click ()"> minimize the window </button>

12. Full Screen code
<Input type = "button" name = "fullscreen" value = "full screen" onclick = "window. Open (document. Location, 'butong _ net ',
'Fullscreen') ">

13. Close the window
<Object ID = closes type = "application/X-oleobject"
Classid = "CLSID: adb880a6-d8ff-11cf-9377-00aa003b7a11"> <Param
Name = "command" value = "close"> </Object> <Input
Type = "button" value = "Close Window"
Onclick = "closes. Click ();">

Close Window
<Input type = button value = Close Window
Onclick = "javascript: Self. Close ()">

14. Maximize
<Object ID = big classid = "CLSID: ADB880A6-D8FF-11CF-9377-00AA003B7A11">

<Param name = "command"
Value = "maximize"> </Object> <input type = button value = maximized onclick = big. Click ()>

15. Disable the Input Method
<Input style = "ime-mode: Disabled" value = Disable the input method>

16. link button 1
<Input type = "button" value = "link button 1"
Onclick = "window. Open ('HTTP: // www.winliuxq.com/', 'sample ',
'Toolbar = No, location = No, directories = No, status = No, menubar = No, scrollbars = No, resizable = Yes, copyhistory = Yes, width = 790, height = 520, Left = 0, Top = 0 ')"
Name = "input">

Link button 2
<Input type = "button" name = "button" value = "link button 2" onclick = "showmodaldialog ('HTTP: // www.winliuxq.com/')">

Link button 3
<Input type = "Submit" value = "link button 3"
Onclick = "location. href = 'HTTP: // www.winliuxq.com/'">

17. The warning box is displayed.Source code
<Button onclickpolicalert(document.doc umentelement. outerhtml)
Style = "width: 110"> the source code is displayed in the warning box </button>

18. Click "clear ".
<Input type = button value = 'print'
Onclick = "This. style. Visibility = 'den den '; window. Print ();">

19. Print
<Input type = button value = 'print'
Onclick = "window. Print ();">

20. Print and preview
<Object classid = "CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2"
Height = 0 id = WB name = WB width = 0> </Object>
<Input type = button value = print preview
Onclick = "wb.exe CWB (7,1)">

21. Save
<Input onclick = "document.execcommand('saveas', 'true', 'common code .htm')" type = button value = Save As>

22. Click auto copy.
<SCRIPT> function ocopy(objpolic{obj.select(;;js=obj.createtextrange(;;;js.exe ccommand ("copy")} </SCRIPT>

<Input type = "text" value = "Click auto copy"
Onclick = "ocopy (this)" size = "11">

23. Automatically Selected
<Input value = "automatically selected"
Onfocus = "This. Select ()" onmouseover = "This. Focus ()"
Size = "11">

24. Open source code
<Button onclick = "document. Location = 'view-Source: '+
Document. Location "size =" 7 "> open source code </button>

25. delayed opening of new windows
<Input type = button value = new window delayed opening
Onclick = javascript: setTimeout ("window. Open ('HTTP: // www.winliuxq.com/')", 10000)>

26. Implement the First Half of the selected text box

<Input type = "text" value = "the first half of the selected text box" size = 30
Onmouseover = "This. Select (); Tr = Document. selection. createRange (); tr. moveend ('character ',-8); tr. Select ();">

<Input type = "text" value = "selected content. For non-ie, you can use this" size = 30 onmouseover = "this. selectionstart = This. value. length-4; this. selectionend = This. value. length ">


27. Click "clear text ".
<Input type = "text" name = "artist" size = 14 value = "click to clear text" onmouseover = This. Focus () onfocus = This. Select ()
Onclick = "If (this. value = 'click to clear text') This. value ='' ">

Click Clear Text
<Input name = Name size = 11 value = click to clear text
Onmouseover = This. focus () onblur = "If (this. value = '') This. value = 'click to clear text' "onfocus = This. select () onclick = "If (this. value = 'click to clear text') This. value = ''">

28. Title ):
<Input type = "text" value = "" id = "AA"
Size = "20">
<SCRIPT> document. getelementbyid ("AA"). value = Document. Title; </SCRIPT>

29. Check whether IE is offline

<Input type = "button" value = "test"
Onclick = "alert (window. Navigator. Online)">

30. 11 refresh button Methods
<Input type = button value = Refresh
Onclick = "history. Go (0)">
<Input type = button value = Refresh onclick = "location. Reload ()">

<Input type = button value = Refresh
Onclick = "location = location">
<Input type = button value = Refresh
Onclick = "location. Assign (location)">
<Input type = button value = Refresh
Onclick = "document.exe ccommand ('refresh')">
<Input type = button value = Refresh
Onclick = "window. navigate (location)">
<Input type = button value = Refresh
Onclick = "location. Replace (location)">
<Input type = button value = Refresh
Onclick = "window. Open ('your own files', '_ Self')">

<Input type = button value = Refresh
Onclick = Document. All. webbrowser. execwb (22, 1)>
<Object classid = CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2 Height = 0
Id = webbrowser width = 0> </Object>
<Form action = "your own files"> <Input
Type = submit value = Refresh> </form>

<A id = A1 href = "your files"> </a> <Input
Type = button value = Refresh onclick = "a1.click ()">

31,
<A href = "#" onclickappsdocument.exe ccommand ("open")> open </a>

32,
<
Onclick = "too many open('i001.htm','', 'height = 300, width = 300, resizable = No, location = net ');"
Href = ""> open a webpage of the specified size </a>

33,
<A href = "#"
Onclick = location. Replace ("view-source:" + location)> edit with notepad </a>

34,
<A href = "#" onclickappsdocument.exe ccommand ("saveas")> Save As </a>

35,
<A href = "#" onclickappsdocument.exe ccommand ("print")> Print </a>
<A href = "javascript: window. Print ();"> Print </a>

36,
<A href = mailto: 429752806@163.com> send e-mail </a>

37,
<A href = "#" onclickappsdocument.exe ccommand ("selectall")> select all </a>

38,
<A href = "#" onclick = location. Reload ()> refresh 1 </a>

39,
<A href = "#" onclick = history. Go (0)> refresh 2 </a>

40,
<A href = "#"
Onclick = location. Replace ("view-source:" + location)> View source files </a>

41,
<A href = "#" onclick = Window. Open (document. Location, "url", "fullscreen")> full screen display </a>

42,
<A href = "#"
Onclick = Window. External. showbrowserui ("privacysettings", null)> Internet Options </a>

43,
<A href = "#" oncontextmenu = "window. Open (this. href); Return
False; "> right-click to open in a new window </a>

44,
<A href = "#" onclick = history. Go (1)> forward 1 </a>

<A href = "#"
Onclick = history. Forward ()> forward 2 </a>

<A href = "#"
Onclick = history. Go (-1)> 1 </a>

<A href = "#"
Onclick = history. Back ()> back 2 </a>

45,
<A href = "#"
Onclick = Window. External. showbrowserui ("organizefavorites", null)> sort favorites </a>

<Span
Onclick = "window. External. AddFavorite ('HTTP: // www.winliuxq.com/', 'webpage special site point')" style = "cursor:
Hand "Title = webpage special effect site> Add to favorites </span>

<A href = "#"
Onclick = "window. External. AddFavorite ('HTTP: // www.winliuxq.com/', 'webpage special site point')"> Add to favorites </a>

<A href = "javascript: window. External. AddFavorite ('HTTP: // www.winliuxq.com /',
'Webpage special effect site') "> click to add to favorites </a>

<A href = "#"
Onmouseover = "window. External. AddFavorite ('HTTP: // www.winliuxq.com/', 'webpage special site ')" target = "_ Self"
> Add your mouse to favorites </a>

<A href = "#"
Onmouseover = "This. style. Behavior = 'url (# default # homepage) '; this. setHomePage ('HTTP: // www.yiloo.com/js /');"
Target = "_ Self"> set mouse to homepage </a>

46,
<A href = "javascript: window. Close ()"> close the window </a>

<A href = "#"
Onclick = Window. Close (); Return false)> close the window </a>

<A href = "#"
Onclick = setTimeout (window. Close (), 3000)> close this window in 3 seconds </a>

<SCRIPT>
Function shutwin (){
Window. Close ();
Return ;}
</SCRIPT>
<A href = "javascript: shutwin ();"> close this window </a>

47. <span onclick = "Var strhref = Window. location. href; this. style. behavior = 'url (# default # homepage) '; this. setHomePage ('HTTP: // www.winliuxq.com /');"
Style = "cursor: Hand"> set as homepage </span>

48. equal to the title bar: <SCRIPT> document. Write (document. Title); </SCRIPT>

49,
<A href = "javascript: void (0 );"
Onclick = 'window. External. AddFavorite (location. href, document. Title); '> Add this page to favorites </a>

<
Href = "javascript: window. External. AddFavorite (document. Location. href,
Document. Title) "> Add this page to favorites </a>

<
Href = javascript: window. External. addchannel ("Typhoon. CDF")> Add channel </a>

50,
<A href = "i003.htm" onclick = "Return false ;"
Ondblclick = "too many open('i003.htm');"> double-click to open the link </a>

51,
<Style> # Close A: hover
{Background: URL (javascript: window. Opener = 0; window. Close () ;}</style> <Div
Id = close> <a href = ""> Close Window </a> </div>

52,
<A href = "javascript: void (0)" onmouseover = "alert ('Sorry, do not select! ') "> The link is not allowed </a>

53. On the left side of the scroll bar, change <HTML> to Dir = "RTL">

54. webpage translucent
<Body style = "filter: alpha (opacity = 50)">

55. Select the background color randomly.
<Body>
<SCRIPT>
Document. body. style. background = (["red", "blue", "pink", "Navy", "gray", "yellow", "green", "Purple"]) [parseint (math. random () * 8)];

</SCRIPT>

56. The scroll bar is not displayed on the frame page:
<SCRIPT>
Self. moveTo (0, 0)
Self. resizeTo (screen. availwidth, screen. availheight)
</SCRIPT>

57. Prevent webpage Frame
<Script language = JavaScript>
If (top. location! = Self. Location ){
Top. Location = self. location;
}
</SCRIPT>

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

59. Automatic window Maximization
<Script language = "JavaScript"> <! --
Self. moveTo (0, 0)
Self. resizeTo (screen. availwidth, screen. availheight)
// --> </SCRIPT>

60. automatically maximize window opening
<Object classid = "CLSID: adb880a6-d8ff-11cf-9377-00aa003b7a11"
Onreadystatechange = "If (this. readystate = 4) This. Click ();"
Viewastext> <Param name = "command"
Value = "maximize"> </Object>

61. eye-catching pop-up code
<SCRIPT> var color = new array; color [1] = "black"; color [2] =
"White"; for (x = 0; x <3; X ++) {document. bgcolor = color [X]; If (x =
2) {x = 0 ;}}</SCRIPT>

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

63. Call the Chinese Character Library
<SCRIPT>
For (I = 19968; I <40870; I ++) document. Write (string. fromcharcode (I ));

</SCRIPT>

64. Script showing the current time
<Script language = VBScript> document. Write now </SCRIPT>

65. Script showing the last modification time
<SCRIPT> document. Write (document. lastmodified) </SCRIPT>

66. Press the F12 key and return directly to the Home Page

<SCRIPT> function look (){
If (event. keycode = 123) {document. Location. href = http://www.winliuxq.com /}

}
If (document. onkeydown = NULL)
{Document. onkeydown = Look}
</SCRIPT>

67. Port Detection

68. Windows that cannot be minimized
<Body onblur = 'self. Focus (); '>

69. Link point external CSS file
<Style> @ import URL ("ie.css"); </style>

70. Embedded framework-call another webpage on a webpage:
<Object type = "text/X-scriptlet" width = "600"
Height = "1000"
Data = "http://www.dushuwu.net/"> </Object>

71. Refresh and change the window size
<Object classid = "CLSID: adb880a6-d8ff-11cf-9377-00aa003b7a11"
Onreadystatechange = "If (this. readystate = 4) This. Click ();"
Viewastext> <Param name = "command"
Value = "maximize"> </Object>

72. Javascript implements vertical dotted lines on webpages
<SCRIPT> Hei = 120; D1 = 2; d2 = 2; cou = math. Floor (HEI/(d1 + D2 ));
Document. Write ('<Table cellspacing = 0 cellpadding = 0 width = 1
Height = '+ Hei +'> ');
For (I = 0; I <cou; I ++) {document. Write ('<tr> <TD Height =' + D2 + '> <tr> <TD
Height = '+ D1 +' bgcolor = 333333> ')} </SCRIPT> </table>

73. js Paging
<SCRIPT> document. Write ("<
Href = "+ location. href. Replace (/\. html/g," _2.html ") +"> 2 </a> "); </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.