Javascript tips (6)

Source: Internet
Author: User
// Custom prompt bar

<A href = "#" Title = "this is the prompt"> tip </a>
<Script language = "JavaScript">
// ************ Default setting definition .*********************
Tpopwait = 50; // The prompt is displayed after the twait Hao seconds.
Tpopshow = 5000; // display the tshow Hao seconds before closing the prompt
Showpopstep = 20;
Popopacity = 99;
// *************** Internal variable definition *****************
Spop = NULL;
Curshow = NULL;
Tfadeout = NULL;
Tfadein = NULL;
Tfadewaiting = NULL;
Document. Write ("<style type = 'text/CSS 'Id = 'defaultpopstyle'> ");
Document. Write (". cpoptext {background-color: # f8f8f5; color: #000000; Border:
1px #000000 solid; font-color: font-size: 12px; padding-Right: 4px; padding-left:
4px; Height: 20px; padding-top: 2px; padding-bottom: 2px; filter:
Alpha (opacity = 0 )}");
Document. Write ("</style> ");
Document. Write ("<Div id = 'dypoplay' style = 'position: absolute; Z-index: 1000 ;'
Class = 'poptext'> </div> ");

Function showpopuptext (){
VaR o = event. srcelement;
Mousex = event. X;
Mousey = event. Y;
If (O. alt! = NULL & O. alt! = "") {O. dypop = O. ALT; O. Alt = ""};
If (O. title! = NULL & O. title! = "") {O. dypop = O. Title; O. Title = ""};
If (O. dypop! = Spop ){
Spop = O. dypop;
Cleartimeout (curshow );
Cleartimeout (tfadeout );
Cleartimeout (tfadein );
Cleartimeout (tfadewaiting );
If (spop = NULL | spop = ""){
Dypoplayer. innerhtml = "";
Dypoplayer. style. Filter = "alpha ()";
Dypoplayer. Filters. Alpha. Opacity = 0;
}
Else {
If (O. dyclass! = NULL) popstyle = O. dyclass
Else popstyle = "cpoptext ";
Curshow = setTimeout ("showit ()", tpopwait );
}
}
}
Function showit (){
Dypoplayer. classname = popstyle;
Dypoplayer. innerhtml = spop;
Popwidth = dypoplayer. clientwidth;
Popheight = dypoplayer. clientheight;
If (mousex + 12 + popwidth> document. Body. clientwidth) popleftadjust =-popWidth-24
Else popleftadjust = 0;
If (Mousey + 12 + popheight> document. Body. clientheight) poptopadjust =-popHeight-24
Else poptopadjust = 0;
Dypoplayer. style. Left = mousex + 12 + document. Body. scrollleft + popleftadjust;
Dypoplayer. style. Top = Mousey + 12 + document. Body. scrolltop + poptopadjust;
Dypoplayer. style. Filter = "alpha (opacity = 0 )";
Fadeout ();
}
Function fadeout (){
If (dypoplayer. Filters. Alpha. Opacity <popopacity ){
Dypoplayer. Filters. Alpha. Opacity + = showpopstep;
Tfadeout = setTimeout ("fadeout ()", 1 );
}
Else {
Dypoplayer. Filters. Alpha. Opacity = popopacity;
Tfadewaiting = setTimeout ("fadein ()", tpopshow );
}
}
Function fadein (){
If (dypoplayer. Filters. Alpha. Opacity> 0 ){
Dypoplayer. Filters. Alpha. Opacity-= 1;
Tfadein = setTimeout ("fadein ()", 1 );
}
}
Document. onmouseover = showpopuptext;
</SCRIPT>
// Insert text
Document. onclick = function (){
VaR osource = Window. event. srcelement;
If (osource. tagname! = "Div ")
Return false;
VaR sel = Document. selection;
If (SEL! = NULL ){
VaR RNG = SEL. createRange ();
If (RNG! = NULL)
RNG. pastehtml ("<font color = Red> insert text </font> ");
}
}
// Operate XML in netscapte
Doc = new activexobject ("msxml2.domdocument ");
Doc = new activexobject ("Microsoft. xmldom ")
->
Doc = (New domparser (). parsefromstring (sxml, 'text/xml ')
// Judge the key value
<HTML>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Head>
<Script language = "JavaScript">
VaR Ie = navigator. appname = "Microsoft Internet Explorer "? True: false;

Function keydown (E)
{
If (! IE)
{
VaR nkey = E. Which;
VaR iekey = 'ns browser now ';
VaR realkey = string. fromcharcode (E. Which );
}
If (IE)
{
VaR iekey = event. keycode;
VaR nkey = 'ie browser now ';
VaR realkey = string. fromcharcode (event. keycode );
If (event. keycode = 32) {realkey = '\ 'space \''}
If (event. keycode = 13) {realkey = '\' press enter \''}
If (event. keycode = 27) {realkey = '\ 'esc \''}
If (event. keycode = 16) {realkey = '\ 'shift \''}
If (event. keycode = 17) {realkey = '\ 'ctrl \''}
If (event. keycode = 18) {realkey = '\ 'alt \''}
}
Alert ('ns browser key value: '+ nkey +' \ n' + 'ie browser key value: '+ iekey +' \ n' + 'actual key is' + realkey );
}
Document. onkeydown = keydown;
</SCRIPT>
</Head>
<Body>
// JavaScript document.
<HR>
<Center>
<H3> press any key .... </H3>
</Center>
</Body>
</Html>
// Disable FSO

1. log out of the component
Regsvr32/u scrrun. dll
2. Modify progid
Hkey_classes_root \ Scripting. FileSystemObject
Scripting. FileSystemObject
3. for users who use objects, modify hkey_classes_root \ Scripting.

// 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>
// Check the media play version.

<Ie: clientcaps id = "oclientcaps" style = "{behavior: URL (# default # clientcaps)}"/>
<SCRIPT>
VaR flash = "";
Wmpversion =
Oclientcaps. GetComponentVersion ("{22d6f312-b0f6-11d0-94ab-0080c74c7e95}", "componentid ");

If (wmpversion! = ""){
Flash = "";
VaR version = wmpversion. Split (",");
VaR I;
For (I = 0; I <version. length; I ++ ){
If (I! = 0)
Flash + = ".";
Flash + = version;
}
Document. Write ("your Windows Media Player version is:" + flash + "<p> ");
}
</SCRIPT>

// Proportional Image

<Script language = "JavaScript">
<! --
// Proportional scaling of the image
VaR flag = false;
Function drawimage (imgd ){
VaR image = new image ();
VaR iwidth = 80; // defines the allowed image width.
VaR iheight = 80; // defines the allowed Image Height
Image. src = imgd. SRC;
If (image. width> 0 & image. Height> 0 ){
Flag = true;
If (image. width/image. Height> = iwidth/iheight ){
If (image. width> iwidth ){
Imgd. width = iwidth;
Imgd. Height = (image. Height * iwidth)/image. width;
} Else {
Imgd. width = image. width;
Imgd. Height = image. height;
}
Imgd. Alt = image. Width + "×" + image. height;
}
Else {
If (image. Height> iheight ){
Imgd. Height = iheight;
Imgd. width = (image. Width * iheight)/image. height;
} Else {
Imgd. width = image. width;
Imgd. Height = image. height;
}
Imgd. Alt = image. Width + "×" + image. height;
}
}
}
// -->
</SCRIPT>

// Fine line select

<Span style = "border: 1px solid #000000; position: absolute; overflow: hidden;">
<Select style = "margin:-2px;">
<Option> 1111 </option>
<Option> 11111111111111 </option>
<Option> 111111111 </option>
</SELECT> </span>

// Import

Function Import () {
for (VAR I = 0; I var file = arguments;
If (file. match (/\. JS $/I)
document. write ('

// JS Enumeration
Function getcomputername ()
{
VaR ob1_miservice = GetObject ("winmgmts: Root \ cimv2 ");
For (E = new enumerator (ob1_miservice );! E. atend (); E. movenext ())
{
VaR getcomputer = E. Item ();
Return getcomputer. Name;
}
}

// Conditional compilation

<Script language = JavaScript>
/* @ Cc_on @*/
/* @ If (@ _ Win32 & @ _ jscript_version> 5)
Function window. Confirm (STR)
{
ExecScript ("n = msgbox ('" + STR + "', 257)", "VBScript ");
Return (n = 1 );
}
@ End @*/
</SCRIPT>

// Get innertext

<Script language = "JavaScript">
<! --
VaR xmldoc = new activexobject ("msxml2.domdocument. 4.0 ");
VaR currnode;
Xmldoc. async = false;
Xmldoc. async = false;
Xmldoc. loadxml ("<tablename> hello, you are a legal representative, legal representative, etc..
</Tablename> ");
Currnode = xmldoc.doc umentelement;

VaR S = currnode. xml;
VaR r =/\ <([^ \> \ s] *?) [^ \>] *? \> ([^ \ <] *?) \ <\/\ 1 \>/
VaR B = S. Replace (R, "$2 ");
Alert (B );
// -->
</SCRIPT>
// Mergeattributes copies all read/write tag attributes to the specified element.
<SCRIPT>
Function fnmerge (){
Osource. Children [1]. mergeattributes (osource. Children [0]);
}
</SCRIPT>
<Span id = osource>
<Div
Id = "odiv"
Attribute1 = "true"
Attribute2 = "true"
Onclick = "alert ('click ');"
Onmouseover = "This. style. Color = '# 0000ff ';"
Onmouseout = "This. style. Color = '#000000 ';"
>
This is a sample <B> Div </B> element.
</Div>
<Div id = "odiv2">
This is another sample <B> Div </B> element.
</Div>
</Span>
<Input
Type = "button"
Value = "merge attributes"
Onclick = "fnmerge ()"
>

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.