73 common JavaScript code for Web pages

Source: Internet
Author: User

73 common JavaScript code for Web pages

Reprinted from: Front End, soul engineer

1, Back forward
<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" onclick= "History.back ( -1)" ></form>

3. View Source code
<input type= "button" name= "View" value= "viewing source" onclick= "window.location=" View-source: "+window.location.href" >

4, forbidden to view the source code
<body oncontextmenu= "return false" ></body>

5. Refresh Button One
<input type= "button" value= "refresh button One" onclick= "Reloadbutton ()" >
<script>function Reloadbutton () {location.href= "i001.htm";} </script>

Refresh Button Two
<input type= "button" value= "refresh button two" onclick= "History.go (0)" >

6. Back to the page button
<input type= "button" value= "Home" onclick= "Homebutton ()" >
<script>function Homebutton () {location.href=http://www.winliuxq.com;} </script>

7. Pop-up warning box
<input type= "button" value= "Pop-up Warning box" onclick= "Alertbutton ()" >
<script>function Alertbutton () {Window.alert ("to visit!") ");} </script>

8. Status Bar Information
<input type= "button" value= "status bar Info" onclick= "Statusbutton ()" >
<script>function Statusbutton () {window.status= "to visit!" ";} </script>

9. Background Color transform
<form><input type= "button" value= "Background color transform" onclick= "Bgbutton ()" ></form>
<script>function Bgbutton () {
if (document.bgcolor== ' #00ffff ')
{document.bgcolor= ' #ffffff ';}
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. Minimized window
<object id= "min" type= "Application/x-oleobject" classid= "Clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" >< PARAM name= "Command" value= "Minimize" ></object><button onclick= "min. Click () > Window minimization </button>

12. Full-screen code
<input type= "button" name= "fullscreen" value= "full screen display" 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. Maximizing
<object id=big classid= "Clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" >
<param name= ' Command ' value= ' maximize ' ></object><input Type=button value= maximize onclick=big. Click () >

15. Close Input Method
<input style= "ime-mode:disabled" value= off input >

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 displays the source code
<button Onclick=alert (Document.documentElement.outerHTML) style= "width:110" > Warning box showing source code </BUTTON>

18. Click the button to empty
<input Type=button value= ' print ' onclick= ' this.style.visibility= ' hidden '; Window.print (); " >

19. Printing
<input Type=button value= ' print ' onclick= ' window.print (); " >

20. Print 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.EXECWB (7,1)" >

21. Save As
<input onclick= "Document.execcommand (' SaveAs ', ' true ', ' common code. htm ') ' Type=button value= Save As >

22. Click Auto Copy
<script>function ocopy (obj) {obj.select (); Js=obj.createtextrange (); Js.execcommand ("Copy")}</script>
<input type= "Text" value= "click on Auto Copy" onclick= "Ocopy (This)" size= ">

23. Automatic selection
<input value= "Automatically check" onfocus= "This.select ()" onmouseover= "This.focus ()" Size= ">

24. Open Source Code
<button onclick= "document.location = ' view-source: ' + document.location ' size=" 7 "> Open source code </BUTTON>

25. Delayed opening of new window
<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= "Select the first half of the contents of the text box" size=30 onmouseover= "This.select (); Tr=document.selection.createrange () ; Tr.moveend (' character ', -8); Tr.select (); " >
<input type= "text" Value= "selected part of the content, non-IE can use this" size=30 onmouseover= "this.selectionstart=this.value.length-4; This.selectionend=this.value.length ">

27. Click to clear the text
<input type= "text" name= "artist" size=14 value= "click to clear the text" Onmouseover=this.focus () onfocus=this.select () onclick= "if (this.value== ' Click to clear Text ') this.value= "" >

Click to clear the 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== ' tap to empty text ') this.value=" ">

28, equal to the title:
<input type= "text" value= "" id= "AA" size= ">
<script>document.getelementbyid ("AA") .value=document.title;</script>

29. Check if IE is offline
<input type= "button" value= "Test" onclick= "alert (window.navigator.onLine)" >

30, 11 Ways to refresh the button
<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.execcommand (' 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 (' 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= "own files" ><input type=submit value= Refresh ></form>
<a id=a1 href= "own files" ></a><input Type=button value= Refresh onclick= "A1.click ()" >

31.
<a href= "#" Onclick=document.execcommand ("open") > Open </a>

32.
<a onclick= "window.open (' i001.htm ', ', ' height=300,width=300,resizable=no,location=net ');" href= "> Open a specified size page </a>

33.
<a href= "#" Onclick=location.replace ("View-source:" +location) > Edit with Notepad </a>

34.
<a href= "#" Onclick=document.execcommand ("SaveAs") > Save As </a>

35.
<a href= "#" Onclick=document.execcommand ("print") > Printing </a>
<a href= "Javascript:window.print (); > Printing </a>

36.
<a href=mailto:[email protected]> Send e-mail</a>

37.
<a href= "#" Onclick=document.execcommand ("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 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) > Back 1</a>

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

45.
<a href= "#" Onclick=window.external.showbrowserui ("organizefavorites", NULL) > Organize Favorites </a>

<span onclick= "Window.external.addFavorite (' http://www.winliuxq.com/', ' web Effects site ')" style= "Cursor:hand" title= Web site effects > Favorites </SPAN>

<a href= "#" onclick= "Window.external.addFavorite (' http://www.winliuxq.com/', ' web Effects site ') ' > Add to Favorites </A>

<a href= "Javascript:window.external.AddFavorite (' http://www.winliuxq.com/', ' web Effects site ')" > Click Add to Favorites </a>

<a href= "#" onmouseover= "Window.external.addFavorite (' http://www.winliuxq.com/', ' web Effects site ')" target= "_self" > Mouse Sensing collection of the site </a>

<a href= "#" onmouseover= "this.style.behavior= ' url (#default #homepage) '; This.sethomepage (' http://www.yiloo.com/ js/'); "target=" _self "> Mouse Sense Set homepage </a>

46.
<a href= "Javascript:window.close ()" > Close window </a>

<a href= "#" Onclick=window.close (); return false) > close window </a>

<a href= "#" Onclick=settimeout (Window.close (), up) >3 sec close this window </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 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); ' > Favorites Page </a>

<a href= "Javascript:window.external.AddFavorite (Document.location.href, Document.title)" > Favorites page </a>

<a Href=javascript:window.external.addchannel ("TYPHOON.CDF") > Join Channel </a>

50.
<a href= "i003.htm" onclick= "return false;" ondblclick= "window.open (' i003.htm ');" > Double-click the Open 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, no check! ')" > Links Prohibited </A>

53. Scroll bar on the left, change
54. Translucent Web Pages
<body style= "Filter:alpha (opacity=50)" >

55. Randomly select the background color
<body>
<script>
Document.body.style.background= (["Red", "Blue", "pink", "Navy", "gray", "yellow", "green", "purple"]) [parseint ( Math.random () *8)];
</script>

56. Scroll bars are not displayed in the frames page:
<SCRIPT>
Self.moveto (0,0)
Self.resizeto (Screen.availwidth,screen.availheight)
</SCRIPT>

57. Prevent Web pages from being framed
<script language=javascript>
if (top.location!== self.location) {
Top.location=self.location;
}
</SCRIPT>

58, will always take the framework
<script language= "JavaScript" ><!--
if (window = = top) Top.location.href = "frame.htm"; Frame.htm for frames page
--></script>

59. Automatic Window Maximization
<script language= "JavaScript" ><!--
Self.moveto (0,0)
Self.resizeto (Screen.availwidth,screen.availheight)
--></script>

60. Automatically maximize the open window
<object classid= "Clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange= "if (this.readyState==4) this. Click (); Viewastext><param name= "Command" value= "Maximize" ></OBJECT>

61, Cool eye splash screen Code
<script>var color = new Array;color[1] = "BLACK"; color[2] = "White", for (x = 0; x <3; + x + +) {Document.bgcolor = Colo R[x];if (x = = 2) {x = 0;}} </script>

62. Cannot be saved as
<noscript><iframe src=*.html></iframe></noscript>

63. Chinese Character Font call
<script>
for (i=19968;i<40870;i++) document.write (String.fromCharCode (i));
</script>

64. Script showing time now
<script Language=vbscript>document.write now</script>

65. Script showing last modified time
<script>document.write (document.lastmodified) </script>

66. Press the F12 button to return to the homepage directly.
<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. Window that cannot be minimized
<body onblur= ' Self.focus (); ' >

69. Link Contact External CSS file
<style> @import url ("ie.css");</style>

70. Inline frame-Call another page in the Web page:
<object type= "Text/x-scriptlet" width= "All" height= "Data=" ></object>

71. Refresh to 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 dashed page
<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 page
<script>document.write ("<a href=" +location.href.replace (/\.html/g, "_2.html") + ">2</a>"); </ Script>

73 common JavaScript code for Web pages

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.