Javascript tips (2)

Source: Internet
Author: User
// Various dimensions
S + = "\ r \ n visible area width of the webpage:" + document. Body. clientwidth;
S + = "\ r \ n visible area of the webpage:" + document. Body. clientheight;
S + = "\ r \ n visible area of the webpage Height:" + document. Body. offsetweight + "(including the width of the edge )";
S + = "\ r \ n visible area height of the webpage:" + document. Body. offsetheight + "(including the width of the edge )";
S + = "\ r \ n webpage body full text width:" + document. Body. scrollwidth;
S + = "\ r \ n webpage text Height:" + document. Body. scrollheight;
S + = "\ r \ n webpage volume Height:" + document. Body. scrolltop;
S + = "\ r \ n left when the webpage is rolled:" + document. Body. scrollleft;
S + = "\ r \ n webpage body part:" + window. screentop;
S + = "\ r \ n left part of the webpage body:" + window. screenleft;
S + = "\ r \ n screen resolution Height:" + window. Screen. height;
S + = "\ r \ n screen resolution width:" + window. Screen. width;
S + = "\ r \ n available workspace Height:" + window. Screen. availheight;
S + = "\ r \ n available workspace width of the screen:" + window. Screen. availwidth;
// Filter numbers
<Input type = text onkeypress = "Return
Event. keycode> = 48 & event. keycode <= 57 | (this. value. indexof ('.') <0? Event. keycode = 46: false )"
Onpaste = "return! ClipboardData. getdata ('text'). Match (/\ D/) "ondragenter =" Return
False ">
// Special Purpose
<Input type = button value = import to favorites
Onclick = "window. External. importexportfavorites (true, 'HTTP: // localhost');">
<Input type = button value = export favorites
Onclick = "window. External. importexportfavorites (false, 'HTTP: // localhost');">
<Input type = button value = favorites
Onclick = "window. External. showbrowserui ('organizefavorites ', null)">
<Input type = button value = language settings
Onclick = "window. External. showbrowserui ('your agedialog ', null)">
<Input type = button value = add to favorites
Onclick = "window. External. AddFavorite ('HTTP: // www.google.com/', 'Google')">
<Input type = button value = add to channel
Onclick = "window. External. addchannel ('HTTP: // www.google.com/')">
<Input type = button value = add to channel
Onclick = "window. External. showbrowserui ('privacysettings', null)">
// No Cache
<Meta HTTP-EQUIV = "Pragma" content = "no-Cache">
<Meta HTTP-EQUIV = "cache-control" content = "no-cache, must-revalidate">
<Meta HTTP-EQUIV = "expires" content = "0">

// Regular Expression matching
Regular Expression matching Chinese characters: [\ u4e00-\ u9fa5]
Match double-byte characters (including Chinese characters): [^ \ x00-\ xFF]
Regular Expression for matching empty rows: \ n [\ s |] * \ r
Regular Expressions matching HTML tags:/<(. *)>. * <\/\ 1> | <(. *) \/>/
Regular Expressions matching spaces at the beginning and end: (^ \ s *) | (\ s * $) (TRIM functions like VBScript)
The regular expression matching the email address: \ W + ([-+.] \ W +) * @ \ W + ([-.] \ W + )*\. \ W + ([-.] \ W + )*
The regular expression matching the URL: http: // ([\ W-] + \.) + [\ W-] + (/[\ W -./? % & =] *)?
The following is an example:
Use regular expressions to restrict text box input in a webpage form:
Use a regular expression to restrict Chinese characters only: onkeyup = "value = value. Replace (/[^ \ u4e00-\ u9fa5]/g ,'')"
Onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text'). Replace (/[^ \ u4e00-\ u9fa5]/g ,''))"

1. Use a regular expression to limit that only full-width characters can be entered: onkeyup = "value = value. Replace (/[^ \ uff00-\ Uffff]/g ,'')"
Onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text'). Replace (/[^ \ uff00-\ Uffff]/g ,''))"

2. Use a regular expression to limit that only numbers can be entered: onkeyup = "value = value. Replace (/[^ \ D]/g ,'')
"Onbeforepaste =" clipboardData. setdata ('text', clipboardData. getdata ('text'). Replace (/[^ \ D]/g ,''))"

3. Use a regular expression to limit that only numbers and English letters can be entered: onkeyup = "value = value. Replace (/[\ W]/g ,'')
"Onbeforepaste =" clipboardData. setdata ('text', clipboardData. getdata ('text'). Replace (/[^ \ D]/g ,''))"

// Remove the image toolbar

Or
<Head>
<Meta http-equiv = "imagetoolbar" content = "no">
</Head>
// No prompt to close

Function close ()
{
VaR UA = navigator. useragent
VaR Ie = navigator. appname = "Microsoft Internet Explorer "? True: false
If (IE)
{
VaR ieversion = parsefloat (UA. substring (UA. indexof ("MSIE
") + 5, UA. indexof ("; ", UA. indexof (" MSIE "))))
If (ieversion <5.5)
{
VaR STR = '<Object ID = notipclose
Classid = "CLSID: ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
STR + = '<Param name = "command" value = "close"> </Object> ';
Document. Body. insertadjacenthtml ("beforeend", STR );
Document. All. notipclose. Click ();
}
Else
{
Window. Opener = NULL;
Window. Close ();
}
}
Else
{
Window. Close ()
}
}
// Obtain the absolute position of the Control (1)

<Script language = "JavaScript">
Function getoffset (E)
{
VaR T = E. offsettop;
VaR L = E. offsetleft;
While (E = E. offsetparent)
{
T + = E. offsettop;
L + = E. offsetleft;
}
VaR rec = new array (1 );
REC [0] = T;
REC [1] = L;
Return rec
}
</SCRIPT>
// Obtain the absolute position of the control (2)
Orect = obj. getboundingclientrect ();
Orect. Left
Orect.
// Minimize, maximize, and close
<Object ID = min classid = "CLSID: ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<Param name = "command" value = "minimize"> </Object>
<Object ID = max classid = "CLSID: ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<Param name = "command" value = "maximize"> </Object>
<Object ID = close classid = "CLSID: adb880a6-d8ff-11cf-9377-00aa003b7a11">
<Param name = "command" value = "close"> </Object>
<Input type = button value = minimized onclick = min. Click ()>
<Input type = button value = maximized onclick = max. Click ()>
<Input type = button value = close onclick = close. Click ()>
// Stop the cursor at the end of the text

<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 ()">
// 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
// 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 ":

// Print the page
<P style = "Page-break-after: Always"> page1 </P>
<P style = "Page-break-after: Always"> page2 </P>

// Set the print

<Object ID = "Factory" style = "display: none" viewastext
Classid = "CLSID: 1663ed61-23eb-11d2-b92f-008048fdd814"
Codebase = "http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"
> </Object>
<Input type = button value = page setting onclick = "factory. Printing. pagesetup ()">
<Input type = button value = print preview onclick = "factory. Printing. Preview ()">

<Script language = JavaScript>
Function window. onload ()
{
// -- Advanced features
Factory. Printing. setmarginmeasure (2) // measure margins in inches
Factory. Printing. setpagerange (false, 1, 3) // need pages from 1 to 3
Factory. Printing. Printer = "HP Deskjet 870c"
Factory. Printing. Copies = 2
Factory. Printing. collate = true
Factory. Printing. papersize = "A4"
Factory. Printing. papersource = "manual feed"
// -- Basic Features
Factory. Printing. header = "center left display & B center right display page number, page & P/total & P"
Factory. Printing. footer = "(custom footer )"
Factory. Printing. Portrait = false
Factory. Printing. leftmargin = 0.75
Factory. Printing. topmargin = 1.5
Factory. Printing. rightmargin = 0.75
Factory. Printing. bottommargin = 1.5
}
Function print (FRAME ){
Factory. Printing. Print (true, frame) // print with prompt
}
</SCRIPT>
<Input type = button value = "print this page" onclick = "factory. Printing. Print (false)">
<Input type = button value = "page setting" onclick = "factory. Printing. pagesetup ()">
<Input type = button value = "print preview" onclick = "factory. Printing. Preview ()"> <br>
<A href = "http://www.meadroid.com/scriptx/docs/printdoc.htm? Static"
Target = _ blank> User Manual. For more information, click here </a>

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.