Tips for JavaScript code on webpages

Source: Internet
Author: User
Tags html encode servervariables

Eliminate form height issues
Style = "margin: 0"

If the content exceeds the cell, it is hidden.
Style = "table-layout: fixed"

Make the pop-up window always at the top: <body onblur = "This. Focus ();">
Do not scroll bars? Make the vertical bar not: <body style = 'overflow: Scroll; overflow-Y: Den den '> </body>
Make the horizontal bar not: <body style = 'overflow: Scroll; overflow-X: Den den '> </body>
Remove both of them? Simpler <body scroll = "no"> </body>
How can I remove the dotted line around the image after clicking the image link? <A href = "#" onfocus = "This. Blur ()"> </a>
Email processing submission form <form name = "form1" method = "Post" Action = "mailto :****@***. com "enctype =" text/plain "> <input type = submit> </form>
In the opening Child Window, how does one refresh the code of the parent window? Window. opener. Location. Reload ()
How to set the page size <body onload = "Top. resizeTo (300,200);">
How to add a background image that is not full? When pulling the page, the background image does not move <HTML>

Various styles of cursor Auto: Standard cursor
Default: Standard arrow
Hand: Hand-shaped cursor
Wait: waiting for the cursor
Text: I-shaped cursor
Vertical-text: horizontal I-shaped cursor
No-drop: Do not drag the cursor
Not-allowed: Invalid cursor
Help :? Help cursor
All-scroll: triangle direction indicator
Move: Move mark
Crosshair: Cross Label E-resize N-resize NW-resize w-resize S-resize se-resize Sw-resize

Local IP address <% = request. servervariables ("remote_addr") %>
Server name <% = request. servervariables ("SERVER_NAME") %>
Server IP <% = request. servervariables ("local_addr") %>
Server port <% = request. servervariables ("server_port") %>
Server time <% = now %> IIS
Version <% = request. servervariables "server_software") %>
Script timeout <% = server. scripttimeout %>
Path of this file <% = server. mappath (request. servervariables ("script_name") %>
Server CPU count <% = request. servervariables ("number_of_processors") %>
Server interpretation engine <% = scriptengine & "/" & scriptenginemajorversion & "." & scriptengineminorversion & "." & scriptenginebuildversion %>
Server Operating System <% = request. servervariables ("OS") %>

Text vertical layout
<Style type = "text/CSS">
<! --
. Shupai {writing-mode: Tb-rl}
-->
</Style>
Move the hyperlink to the dotted border
Add onfocus = "This. Blur ()" to the link ()"

Insert a keyword in the Webpage Search Header
<Meta name = "keywords" content = "XXXX, xxxx, XXX, XXXXX, xxxx,">

Favorites icon
<LINK rel = "shortcut icon" href = "favicon. ICO">

My computer
File: // ::{ 20d04fe0-3aea-1069-a2d8-08002b30309d}
Network neighbors
File: //: % 7b208d2c60-3aea-1069-a2d7-08002b30309d % 7D
My Documents
File: //: % 7b450d8fba-ad25-11d0-98a8-0800361b1103% 7D
Control Panel
File: //: {20d04fe0-3aea-1069-a2d8-08002b30309d}/: {21ec2020-3aea-1069-a2dd-08002b30309d}
Recycle Bin
File: //: % 7b645ff040-5081-101b-9f08-00aa002f954e % 7D

Control the image hiding effect with the mouse
Add the following code to the <body> area:
<Script language = "JavaScript">
<! --
Function makevisible (cur, which ){
If (which = 0)
Cur. Filters. Alpha. Opacity = 100
Else
Cur. Filters. Alpha. Opacity = 20
}
// -->
</SCRIPT>
2. Add the following code to the <body> area:
Onmouseover = "makevisible (this, 0 )"
Onmouseout = "makevisible (this, 1)">

Disable image download
<A href = "javascript: void (0)" onmouseover = "alert ('Sorry, this image cannot be downloaded! ') ">
</a>

Page embedding
<IFRAME width = 291 Height = 247 src = "Main. Files/news.htm" frameborder = 0> </iframe>

Hide a scroll bar
<Body style = "overflow-X: hidden; overflow-Y: hidden"

CSS text shadow (defined in <TD>)
. ABC {
Filter: dropshadow (color = #666666, offx = 1, offy = 1, positive = 1); font-family: ""; font-size: 9pt; color: # ffffff;
}

LIST/menu
Onchange = "location = This. Options [This. selectedindex]. Value"

<IFRAME id = "frm" src = "k-xinwen.html" scrolling = "no" width = "314" Height = "179"> </iframe>

Reurl=server.html encode (request. servervariables ("http_referer "))

How to define connections on the server
Mm_www_string = "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & server. mappath ("../data/www. mdb ")

Link
Response. Redirect "login. asp"
Location. href = "XX. asp"

Onclick = "window. Location = 'login. asp '"
Onclick = "window. Open ('')"

Get IP
Userip = request. servervariables ("http_x_forwarded_for ")
If userip = "" Then userip = request. servervariables ("remote_addr ")

SQL = "Update feedbak set hit = hit + 1 where id =" & request ("ID ")
Conn.exe cute (SQL)

Whether to add the truncation character...
Function formatstr (STR, Len)
If (LEN (STR)> Len)
STR = left (STR, Len) + "..."
End if
Formatstr = Str
End Function

Receiving form
If ucase (request. servervariables ("request_method") = "Post" then
End if

Image Width
<Script language = "JavaScript">
<! --
VaR flag = false;
Function drawimage (CKP ){
VaR image = new image ();
Image. src = CKP. SRC;
If (image. width> 0 & image. Height> 0)
{Flag = true;
If (image. width> 120 ){
CKP. width = 120;
} Else {
CKP. width = image. width;
}
CKP. Alt = image. Width + "×" + image. height;
}
}
// -->
</SCRIPT>
'I will be back 22:18:06
/<% = RS (" photoname ") %>" border = "0" onLoad = "javascript: drawimage (this ); ">

Jump
<Meta http-equiv = Refresh content = '0; url =/Distributor/distributor. aspx '>

Overflow bar settings
Visible: the excess parts are displayed;
Hidden: Hide the excess parts;
Scrool: the scroll bar is displayed no matter whether it exceeds the limit;
Auto: the scroll bar is displayed only when the value exceeds the upper limit;

Onmouseover: move the mouse over the target;
Onmouseup: When you press the mouse and then open the left button;
Onmouseout: When the mouse is removed;
Onmousedown: When you press the mouse (you do not need to open the left button );
Onclink: click it;
Ondblclick: Double-click;
Onload: when loading a webpage;
OnUnload: When the page is left;
Onresize: When the browser changes the browsing window size;
Onscroll: When the viewer drags the scroll bar.

CSS style
A: Link: the link has been connected;
A: hover: indicates moving the link over the mouse;
A: active: indicates that the link is activated;
A: visited: indicates the link you have clicked.

Pop-up dialog box Link
Javascript: Alert ('lajflsjpjwg ')
Back: javascript: history. Back (1)
Close Window: javascript: window. Close ();
Restore window
Function restore (){
Window. moveTo (8, 8 );
Window. resizeTo (screen. Width-24, screen. availHeight-24 );
}

The head area refers to the content between Tags that must be added

1. Company copyright note
<! --- The site is designed by maketown, INC 06/2000 --->

2. webpage display character set
<Meta HTTP-EQUIV = "Content-Type" content = "text/html; charset = gb2312">
Traditional Chinese: <meta HTTP-EQUIV = "Content-Type" content = "text/html; charset = big5">
English: <meta HTTP-EQUIV = "Content-Type" content = "text/html; charset = iso-8859-1">

3. webpage producer Information
<Meta name = "author" content = "webmaster@maketown.com">

4. Website Introduction
<Meta name = "Description" content = "xxxxxxxxxxxxxxxxxxxxxxxx">

5. Search for keywords
<Meta name = "keywords" content = "XXXX, xxxx, XXX, XXXXX, xxxx,">

6. CSS specifications for webpages
<Link href = "style/style.css" rel = "stylesheet" type = "text/CSS">
(See directory and naming rules)

7. webpage title
<Title> xxxxxxxxxxxxxxxxxx </title>

. You can select the added tag.

1. Set the expiration time of the webpage. Once the webpage expires, you must re-access it on the server.
<Meta HTTP-EQUIV = "expires" content = "wed, 26 Feb 1997 08:21:57 GMT">

2. Disable the browser from accessing the page content from the cache on the local machine.
<Meta HTTP-EQUIV = "Pragma" content = "no-Cache">

3. It is used to prevent others from calling your page in the framework.
<Meta HTTP-EQUIV = "window-target" content = "_ top">

4. Automatic jump.
<Meta HTTP-EQUIV = "refresh" content = "5; url = http://www.yahoo.com">
5 indicates that the time is 5 seconds.

5. The web search robot wizard is used to tell robots which pages need to be indexed and which pages do not need to be indexed.
<Meta name = "Robots" content = "NONE">
Content parameters include all, none, index, noindex, follow, and nofollow. The default value is all.

6. favorites icon
<LINK rel = "shortcut icon" href = "favicon. ICO">

All JavaScript calls should adopt external calls as much as possible.
<Script language = "JavaScript" src = "script/XXXXX. js"> </SCRIPT>

Attached <body> label:
<Body> the tag does not belong to the head area. To ensure browser compatibility, you must set the page background. <body bgcolor = "# ffffff">

Flash transparency
Add <Param name = "wmode" value = "Transparent">

Table transparency
Style = "filter: alpha (opacity = 72 )"

How to add an icon before a URL
1. Create an icon on the http://www.favicon.com with his icon editor online. He will send the completed icons to you by email.
2. Place the icon named favicon.icoin the same folder as index.html. You can.
As an icon file, the size is 16*16 pixels. The file extension is ICO and then uploaded to the corresponding directory. Add the following code between the HTML source file "<LINK rel = "shortcut icon" href = "http: // image address (corresponding to the directory just now)">
The "shortcut cut icon" is the name of the icon. Of course, if you use ie5 or a later version for browsing, it will be simpler. You only need to upload the image to the root directory of the website for automatic identification.

<LINK rel = "bookmark" href = "favicon. ICO">

Status Bar Connection description
<A href = "link to somewhere" onmouseover = "window. status = 'Connection description'; return true; "onmouseout =" window. status = '';"> XX link </a>

Link Description
<A href = "" Title = Link Description>

Right-click prohibited
Add <body oncontextmenu = "Return false"> to the <body> label.

Enter space in DW
Insert N & nbsp;

Horizontal line
<HR width = "length" size = "height" color = "color code" noshade> noshade indicates whether shadow exists.

Form email submission
<Form name = "content" method = "Post" Action = "mailto: email"> </form>
The text domain name is subject as the mail title

Custom Email links
Mailto: address? Subject = Email Title & BC = CC & BCC = BCC

Background Music
<Bgsound src = address loop = "-1">

Disable page Body Selection
<Body oncontextmenu = "Return false" ondragstart = "Return false" onselectstart = "Return false" onselect = "document. selection. empty () "oncopy =" document. selection. empty () "onbeforecopy =" Return false "onmouseup =" document. selection. empty () ">

Remove the image toolbar that automatically appears in IE6 and set the galleryimg attribute to false or no.

When you click an empty link, the page is often reset to the top.
The Code "javascript: void (null)" replaces the original "#" mark

How to prevent others from placing your webpage in the framework
<Script language = "JavaScript"> <! -- If (self! = Top) {top. Location = self. Location;} --> </SCRIPT>

Page timed refresh
<Meta http-equiv = "refresh" content = "seconds">

The page is switched to a new address at regular intervals.
<Meta http-equiv = "refresh" content = "seconds; url = URL">

Display date
<Script language = "JavaScript"> <! --
Today = new date ();
VaR week; var date;
If (today. getday () = 0) Week = "Sunday"
If (today. getday () = 1) Week = "Monday"
If (today. getday () = 2) Week = "Tuesday"
If (today. getday () = 3) Week = "Wednesday"
If (today. getday () = 4) Week = "Thursday"
If (today. getday () = 5) Week = "Friday"
If (today. getday () = 6) Week = "Saturday"
Date = (today. getyear () + "year" + (today. getmonth () + 1) + "month" + today. getdate () + "day" + ""
Document. Write ("<span style = 'font-size: 9pt; '>" + date + week + "</span> ");
// -->
</SCRIPT>

Set as Homepage
<A href = # onclick = "this. style. behavior = 'url (# default # homepage) '; this. setHomePage ('url'); "> set as homepage </a>

Add to favorites
<A href = "javascript: window. External. AddFavorite ('url', 'title')"> Add to favorites </a>

Text scroll
Insert a table with one row and one column with a border of 0, Enter text in the table, select text,
Press Ctrl + T and enter marquee ction = "up". Press enter to scroll up the text in the table area.
(Right and down can be used to scroll the text or image to the right and down. modifying the original HTML code can also get the desired rolling speed.

Form Verification
<Script language = JavaScript>
Function checkform (theform ){
If (theform. Name. value = ""){
Alert ("name cannot be blank! ");
Theform. Name. Focus ();
Return false;
}
If (theform. Tel. value = ""){
Alert ("the phone number cannot be blank! ");
Theform. Tel. Focus ();
Return false;
}
}
</SCRIPT>

Define mouse
Body {cursor: URL (cur. Ani or cur );}

Insert videos as images

Layer on flash
<Param name = "wmode" value = "Opaque">

Delayed jump
<Meta http-equiv = Refresh content = '3; url = javascript: window. Close (); '>

Navigation bar color change:
Insert onmouseover = "javascript: This. bgcolor = '# 57ae00'" onmouseout = "javascript: This. bgcolor =' # 99ccff'" after the cell <TR '"

Center
<Center> </center>

Empty Link
Javascript :;

Title table
<Fieldset>
<Legend> table description </legend>
</Fieldset>

Line table
Style = "border-collapse: collapse ;"

Color Code of the scroll bar
Body {
SCROLLBAR-FACE-COLOR: # ffffff;
SCROLLBAR-HIGHLIGHT-COLOR: # ffffff;
SCROLLBAR-SHADOW-COLOR: # ffffff;
SCROLLBAR-3DLIGHT-COLOR: # ffcbc8;
SCROLLBAR-ARROW-COLOR: # ffffff;
SCROLLBAR-TRACK-COLOR: # ffffff;
SCROLLBAR-DARKSHADOW-COLOR: # ffcbc8;
SCROLLBAR-BASE-COLOR: # ffffff
}

Continuous English or a bunch of exclamation marks !!! Will not automatically wrap
As long as the following sentence is defined in CSS, the web page will no longer be supported

Table {table-layout: fixed ;}
TD {word-break: Break-all; Word-wrap: Break-word ;}

Note:

1. The first table {table-layout: fixed;}. This style can be included in the table !!! Automatically wrap a line when a character such as an exclamation point (Exclamation point.

2. TD {word-break: Break-all}. This statement is usually used, but it will be supported in some special circumstances, therefore, you need to add the following sentence {word-wrap: Break-word;} to solve the problem. This style can automatically wrap some consecutive English words in the table.

 

Related Article

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.