Common JavaScript code (7) and javascript code

Source: Internet
Author: User

Common JavaScript code (7) and javascript code
Article from "PHP Chinese network"


64. Document path
Document. URL //

65. regularly execute a program
Settime out ("change_color ()", 600 );

66. Set as home page
Function makeHome (){
Netscape. security. PrivilegeManager. enablePrivilege ("UniversalPreferencesWrite ");
Navigator. preference ("browser. startup. homepage", location. href );
}//

67. Set to favorites
Function addFav (){
If (ie)
Window. external. AddFavorite (location. href, 'www. OGRISH. COM: grotesque movies and Pictures ');
If (ns)
Alert ("Thanks for the bookmark! \ N \ nNetscape users click OK then press CTRL-D ");
}//

68. Determine whether the cookie is available
Navigator. cookieEnabled ;//

69. display the pop-up window with a mode and a page
Function setbgcolor_onclick ()
{
Var color = showModalDialog ("/mailpage/compose/colorsel.html", 0, "help = 0 ");
If (color! = Null)
{
Document. compose. bgcolor. value = color;
}
}//


70. Extract the last two digits of the decimal point
Var a = 3454545.4454545;
Alert (a. toFixed (2 ));//


71. Do not select text on the page to copy
<Script>
Function noEffect (){
With (event ){
ReturnValue = false;
CancelBubble = true;
}
Return;
}
</Script>
<Body onselectstart = "noEffect ()" oncontextmenu = "noEffect ()"> //

72. shield the right-click menu
Oncontextmenu = "event. returnValue = false "//

73. Blister prohibited in the event
Event. cancelBubble = true //

74. do not enable the input method in the input box.
<Input style = "ime-mode: disabled"> //

75. Shielding Chinese characters and spaces
<Input name = "txt"> <input type = "submit" onClick = "alert (! /[^-}] | \ S/. test (txt. value) "> //

76. use javascript to determine whether a file exists
Function Exists (filespec)
{
If (filespec)
{
Var fso;
Fso = new ActiveXObject ("Scripting. FileSystemObject ");
Alert (fso. FileExists (filespec ));
}
}
Select an image <input type = file name = f1> <p>
<Input type = "submit" onClick = "Exists (f1.value)"> //

77. Obtain the selected text in the current text box
<Input onmouseup = "alert (document. selection. createRange (). text)" value = 123> //

78. Jump to the target page and do not return
<A href = "javascript: location. replace ('HTTP: // www.sohu.com/')"> sohu.com </a> //


79. Obtain the row number of the table.
<Script>
Function getrow (obj)
{
If (event. srcElement. tagName = "TD "){
CurRow = event. srcElement. parentElement;
Alert ("This is the first" + (curRow. rowIndex + 1) + "row ");

}
}
</Script>

<Table border = "1" width = "100%" onclick = getrow (this)>
<Tr>
<Td width = "20%"> </td>
<Td width = "20%"> </td>
<Td width = "20%"> </td>
<Td width = "20%"> </td>
<Td width = "20%"> </td>
</Tr>
<Tr>
<Td width = "20%"> </td>
<Td width = "20%"> </td>
<Td width = "20%"> </td>
<Td width = "20%"> </td>
<Td width = "20%"> </td>
</Tr>
</Table> //

80. delete a row in the table. xx indicates a row. The subscript starts from 0.
Document. all. myTable. deleteRow (xx )//

81. dynamically Add rows to the table
<Table id = "t1" border = "1">
</Table>
<Script language = "JavaScript">
Function add ()
{
T1.insertRow (). insertCell (). innerHTML = '<input name = "test' + t1.rows. length +'"> ';
}//



82. Differences between event. x, event. clientX, and event. offsetX:
X: set or obtain the position of the outer boundary of the parent element of the mouse relative to the target event on the x coordinate. ClientX: The x coordinate position relative to the customer region. No

Including the scroll bar, that is, the body area. Offsetx: set or obtain the position of the inner boundary of the parent element of the mouse relative to the target event on the x coordinate.
ScreenX: relative to the user screen.


83. Which of the following buttons is displayed?
<Body onMouseDown = "alert (event. button)"> click "Mouse //

84. Open drive C
<Form action = "file: // c |/"> <input type = "submit" value = "c: \ drive"> </form> //

85. Current screen resolution
Screen. width, screen. height //

86. Set the content in the table
Tbl. rows [0]. cells [1]. innerText = document. form. text1.value ;//


87. Local shortcut
<P> <a href = "file: //: {208D2C60-3AEA-1069-A2D7-08002B30309D}" target = "_ blank"> network neighbors </a> </p>
<P> <a href = "file: //: {20D04FE0-3AEA-1069-A2D8-08002B30309D} \ d: \ web "target =" _ blank "> my computer </a> </p>
<P> <a href = "file: // :{ export d8fba-ad25-11d0-98a8-0800361b1103}" target = "_ blank"> my documents </a> </p>
<P> <a href = "file: // :{ 645FF040-5081-101B-9F08-00AA002F954E}" target = "_ blank"> recycle bin </a> </p>
<P> <a href = "file: //: {20D04FE0-3AEA-1069-A2D8-08002B30309D} \: {21EC2020-3AEA-1069-A2DD-08002B30309D }"

Target = "_ blank"> Control Panel </a> </p>
<P> <a href = "file: //: {7007ACC7-3202-11D1-AAD2-00805FC1270E}"> Dial-Up Network </a> (Windows 2000) </p>


88. IE menu
<Button onclick = "min. Click ()"> <font face = "webdings"> 0 </font> </button> // change the image on the button
<Input type = button onclick = "document.exe cCommand ('createlink ', 'true', 'true')"> // create a new connection
<Input type = button onclick = "document.exe cCommand ('print ', 'true', 'true')"> // print
<Input type = button onclick = "document.execcommand('saveas', 'true', 'website creation .htm ')"> // save it as htm
<Input type = button onclick = "document.execcommand('saveas', 'true', 'website creation .txt ')"> // save it as txt
Document.exe cCommand ("SaveAs") // save
Document.exe cCommand ('undo ') // undo the last operation

89. web dialog box
<SCRIPT>
Var contents = '<style> body, td {font: menu} img {cursor: hand} </style> ';
Contents + = '<title> do you want to close me </title> ';
Contents + = '<body bgcolor = menu> ';
Contents + = '<table width = 100% height = 100% border = 0> ';
Contents + = '<tr> <td align = center> ';
Contents + = 'Do You Want To close me? <Br> ';
Contents + = ' ';
Contents + = ' ';
Contents + = '</td> </tr> </table> ';
ShowModalDialog ("about:" + contents + "", "", "dialogHeight: 50px; dialogWidth: 250px; help: no; status: no ")
Document. write (contents );
</SCRIPT> //

90. Take the value of x and y.
<Button onclick = "t1.rows [x]. cells [y]. innerText = 'guoguo'"> </button> //

91. Write content to the newly opened webpage
Newwin = window. open ('about: blank ', '', 'top = 10 ');
Newwin.doc ument. write ('');//

93. Return
Javascript: history. go (-2 );//

94. Copy the selected content to the clipboard.
Abcdefg
<Input type = 'button'

Onclick = "window. clipboardData. setData ('text', document. selection. createRange (). text);" value = 'selected on the copy page

'> //
95. Copy the selected content on the page to the clipboard.
<Input type = "text" NAME = ""> kjhkjhkhkj <input type = "button" onclick = "document.exe cCommand ('copy', 'false ',

Null); "> ////

96. All opened automatically when the mouse is moved to the drop-down box
<Select onmouseover = "javascript: this. size = this. length" onmouseout = "javascript: this. size = 1"> </select> //

97. Get local files
Var fso = new ActiveXObject ("Scripting. FileSystemObject ");
Var f1 = fso. GetFile ("C: \ bsitcdata \ ejbhome. xml ");
Alert ("File last modified:" + f1.DateLastModified );//

98. Determine whether the client is an IE browser
Because document. all is a special attribute of IE, this method is usually used to determine whether the client is an IE browser, document. all? 1:0;

99. Create a New drop-down box option
New Option (text, value) functions //

100. Draw a bar chart on the page
<STYLE>
Td {font-size: 12px}
Body {font-size: 12px}
V \: * {behavior: url (# default # VML);} // v is declared as a VML public variable.
</STYLE>
<Script language = "JavaScript">
Mathstr = 12;
Document. write ("<v: rect fillcolor = 'red'

Style = 'width: 20; color: navy; height: "+ 5000/(1000/mathstr) + "'> <br> %" + mathstr + "<br> 4 <v: Extrusion

Backdepth = '15pt' on = 'true'/> </v: rect> ")
</SCRIPT>
<V: rect fillcolor = 'red' style = 'width: 20; color: navy; height: 200 '> <br> % 12 <br> 4 people <v: Extrusion

Backdepth = '15pt' on = 'true'/> </v: rect>
<V: rect fillcolor = 'yellow' style = 'width: 20; color: navy; height: 100 '> <br> % 12 <br> 4 people <v: Extrusion

Backdepth = '15pt' on = 'true'/> </v: rect> //

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.