Common JavaScript code

Source: Internet
Author: User

 

// Special Purpose

<Input type = button value = import 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 setting onclick = "window. External. showbrowserui ('languagedialog ', 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 Expression matching spaces at the beginning and end: (^ s *) | (S * $) (TRIM function like VBScript)
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:
You can only enter Chinese characters using regular expressions: onkeyup = "value = value. replace (/[^ u4E00-u9FA5]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ u4E00-u9FA5]/g ,''))"

1. you can only enter the full-width characters: 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. you can only enter numbers and English letters using regular expressions: onkeyup = "value = value. replace (/[w]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ d]/g ,''))"

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

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

// Embedded print preview
Webbrowser. execwb () Open
Web. execwb () Close all existing IE Windows and open a new window
Web. execwb () save Web Page
Web. execwb (6, 1) Printing
Web. execwb (7,1) print and preview
Web. execwb (8, 1) Printing page settings
Web. execwb () view page properties
Web. execwb () seems to be undo, to be confirmed
Select all web. execwb ()
Web. execwb (22, 1) Refresh
Web. execwb () Close form no prompt
<Style media = print>
. Noprint {display: None ;}<! -- Hide non-print items when printing with this style -->
. Pagenext {page-break-after: Always ;}<! -- Control pagination -->
</Style>
<Object ID = "webbrowser" width = 0 Height = 0 classid = "CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2">

</Object>

<Center class = "noprint">
<Input type = button value = print onclick = Document. All. webbrowser. execwb (6, 1)>
<Input type = button value = print onclick = Document. All. webbrowser. execwb (6, 6)>
<Input type = button value = page setting onclick = Document. All. webbrowser. execwb (8, 1)>
</P>
<P> <input type = button value = print preview onclick = Document. All. webbrowser. execwb (7,1)>
</Center>

 

// Remove the header and footer when printing

<Script language = "JavaScript">
VaR hkey_root, hkey_path, hkey_key;
Hkey_root = "HKEY_CURRENT_USER ";
Hkey_path = "softwaremicrosoftinternet assumerpagesetup ";
// Set the page header and footer to be empty.
Function pagesetup_null ()
{
Try
{
VaR wsh = new activexobject ("wscript. Shell ");
Hkey_key = "Header ";
Wsh. regwrite (hkey_root + hkey_path + hkey_key ,"");
Hkey_key = "footer ";
Wsh. regwrite (hkey_root + hkey_path + hkey_key ,"");
}
Catch (e ){}
}
// Set the page header and footer to the default value.
Function pagesetup_default ()
{
Try
{
VaR wsh = new activexobject ("wscript. Shell ");
Hkey_key = "Header ";
Wsh. regwrite (hkey_root + hkey_path + hkey_key, "& W & B page number, & P/& P ");
Hkey_key = "footer ";
Wsh. regwrite (hkey_root + hkey_path + hkey_key, "& U & B & D ");
}
Catch (e ){}
}
</SCRIPT>
<Input type = "button" value = "Clear page number" onclick = pagesetup_null ()>
<Input type = "button" value = "Restore page number" onclick = pagesetup_default ()>

// Mask the button
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<NoScript> <meta http-equiv = "refresh" content = "0; url = about: NoScript"> </NoScript>

<Title> right-click, CTRL + N, Shift + F10, ALT + F4, F11, F5 refresh, and backspace </title>
</Head>
<Body>
<Script language = "JavaScript"> <! --
// Shield right-click, CTRL + N, Shift + F10, F11, F5 refresh, and return keys
// Author: meizz (plum blossom rain) 2002-6-18
Function document. oncontextmenu () {event. returnvalue = false;} // right-click the screen
Function window. onhelp () {return false} // block F1 help
Function document. onkeydown ()
{
If (window. event. altkey )&&
(Window. event. keycode = 37) | // mask Alt + direction key seek
(Window. event. keycode = 39) // mask Alt + direction key →
{
Alert ("You are not allowed to use Alt + arrow keys to move forward or backward the webpage! ");
Event. returnvalue = false;
}
/* Note: this does not really block Alt + direction keys,
Because when the Alt + direction key pop-up warning box is displayed, press and hold the Alt key,
With the mouse clicked off the warning box, this blocking method will become invalid. If
Which of the following methods does the master really block the Alt key. */
If (event. keycode = 8) | // shield the unregeed deletion key
(Event. keycode = 116) | // block the F5 refresh key
(Event. ctrlkey & event. keycode = 82) {// Ctrl + R
Event. keycode = 0;
Event. returnvalue = false;
}
If (event. keycode = 122) {event. keycode = 0; event. returnvalue = false;} // block F11
If (event. ctrlkey & event. keycode = 78) event. returnvalue = false; // block Ctrl + n
If (event. shiftkey & event. keycode = 121) event. returnvalue = false; // block SHIFT + F10

If (window. event. srcelement. tagname = "A" & window. event. shiftkey)
Window. event. returnvalue = false; // block shift with the left mouse button to open a new page
If (window. event. altkey) & (window. event. keycode = 115) // block Alt + F4
{
Window. showmodelessdialog ("about: blank", "", "dialogwidth: 1px; dialogheight: 1px ");

Return false;
}
}
</SCRIPT>
Shield right-click, CTRL + N, Shift + F10, ALT + F4, F11, F5 refresh, and return key
</Body>
</Html>

// Print the screen
<Style>
@ Media Print {
* {Display: None}
}
</Style>

// Ellipsis

<Div style = "width: 120px; Height: 50px; Border: 1px solid blue;
Overflow: hidden; text-overflow: ellipsis ">
<Nobr> for example, a row of text is long and cannot be displayed in a table. </nobr>
</Div>

// Move the layer and drag it.

1. <span style = 'position: absolute; width: 200; Height: 200; Background: red' onmousedown = mousedown (this) onmousemove = mousemove () onmouseup = mouseup ()> meizz </span>

<Script language = JavaScript>
VaR OBJ;
Function mousedown (OBJ)
{
OBJ = OBJ;
OBJ. setcapture ();
OBJ. L = events. x-Obj.style.pixelLeft;
OBJ. t = event. y-Obj.style.pixelTop;
}
Function mousemove ()
{
If (OBJ! = NULL)
{
OBJ. style. Left = events. x-Obj.l;
OBJ. style. Top = activity. y-Obj.t;
}
}
Function mouseup ()
{
If (OBJ! = NULL)
{
OBJ. releasecapture ();
OBJ = NULL;
}
}
</SCRIPT>
2.
<Div id = "mydiv" src = "logo.gif" ondrag = "dodrag ();" onmouseover = "this. style. cursor = 'hand' "style =" position: absolute; left = 100; Top = 100; "onmousedown =" domousedown (); ">

<A href = "#" onclick = "Return false"> </Div>
<Script language = "JavaScript" type = "text/JavaScript">
VaR orgmousex;
VaR orgmousey;
VaR orgobjx;
VaR orgobjy;
Function dodrag ()
{
VaR myobject = Document. All. mydiv;

VaR x = event. clientx;
Var y = event. clienty;
Myobject. style. Left = x-(orgmousex-orgobjx );
Myobject. style. Top = Y-(orgmousey-orgobjy );

}
Function domousedown ()
{
Orgmousex = event. clientx;
Orgmousey = event. clienty;
Orgobjx = parseint (document. All. mydiv. style. Left );
Orgobjy = parseint (document. All. mydiv. style. Top );
}

</SCRIPT>

// Download an object

Function downurl (strremoteurl, strlocalurl)
{
Try
{
VaR XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
XMLHTTP. Open ("get", strremoteurl, false );
XMLHTTP. Send ();
VaR adodbstream = new activexobject ("ADODB. Stream ");
Adodbstream. type = 1; // 1 = adtypebinary
Adodbstream. open ();
Adodbstream. Write (XMLHTTP. responsebody );
Adodbstream. savetofile (strlocalurl, 2 );
Adodbstream. Close ();
Adodbstream = NULL;
XMLHTTP = NULL;

}
Catch (E)
{
Window. Confirm ("An error occurred while downloading the URL! ");
}
// Window. Confirm ("download completed .");
}

// Check whether the connection is valid

Function getxml (URL)
{
VaR XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
XMLHTTP. Open ("get", URL, false );
Try
{
XMLHTTP. Send ();
}
Catch (e ){}
Finally
{
VaR result = XMLHTTP. responsetext;
If (result)
{
If (XMLHTTP. Status = 200)
{
Return (true );
}
Else
{
Return (false );
}
}
Else
{
Return (false );
}
}
}

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.