Common Code in ASP-based Web Development

Source: Internet
Author: User
Tags servervariables

<! -- Make the table have the connection function --->
<Html>
<Head>
<Title> HTML document </title>
</Head>
<Body>
<Table border = "1" cellpadding = "0" cellspacing = "0" width = "200" height = "200" bgcolor = "Gray"> <tr> <td onmouseover = this. bgColor = "#800000" onclick = window. location. href = "http://www.google.com"> google </td> </tr> <td onmouseover = this. bgColor = "#008000" onclick = window. location. href = "http://www.blueidea.com"> bluidea. c... 0 "onclick = window. location. href = "http://www.blueidea.com/bbs"> bbs </td> </tr> </table>
</Body>
</Html>

<%
'Get the URL value and jump to the new URL
Dim a, B
A = request. querystring ("boardID ")
B = request. querystring ("id ")
Response. redirect ("http://bbs.anquan.com.cn/dispbbs.asp? Boardid... "& id =" & B)
%>

<% @ Language = VBScript %>
<Html>
<Title> No. 2 is determined based on the remote host address. If it is a local address, the welcome page is displayed; otherwise, an error message is displayed. </title>
<Body>

Local ip Address
<% = Request. ServerVariables ("REMOTE_ADDR") %>
Server IP Address
<% = Request. ServerVariables ("LOCAL_ADDR") %>
<%
Dim address
Address = request. servervariables ("REMOTE_ADDR ")
Response. write address
If address = "127.0.0.1" then
'If it is local, the welcome page is displayed.
Response. write "Hello, welcome to this site ."
'Response. redirect "http: // localhost/100asp/001.asp"
Else
'Otherwise, the error message is displayed.
Response. write "sorry, you do not have permission to view the internal site ."
End if
%>
</Body>
</Html>

'Judge by time, display the latest flag
<%
Mytime = rs ("time") 'database storage time
Nowtime = now () 'current time
If datediff ("d", mytime, nowtime) <1 then
'Compares the current time with the time in the data warehouse. If the difference is smaller than 1, the image new.gif is displayed.
%>

<% End if %>

'The Method of Auto-shrinking when the image size is large.
120) this. width = 120 "alt =" <% = trs ("e_trem") %> ">

'Writing several conditional statements
While ...... wend
Do while ...... loop
Yes
If ...... else end if
If ...... elseif end if

'Long title truncation method 1
<% If len (rs ("showname")> 13 then %>
<% = Left (rs ("showname"), 12) %> ..
<% Else %>
<% = Rs ("showname") %>
<% End if %>
'Statement 2
<% If len (rs ("quizTitle")> 13 then response. write left (rs ("quizTitle"), 12 )&".. "else response. write rs ("quizTitle") end if %>

'Prompt the statement after an error or operation is completed.
<%
Response. write "<script language = javascript> alert ('Leave a message! '); Window. location. href = 'liuyan. asp'; </script>"
%>
<%
Response. write "<script language = JavaScript>" & chr (13) & "alert ('check whether the content you entered is complete! '); "&" History. back () "&" </script>"
%>

'Convert the limited categories in the table into "Chinese characters"
<%
Dim quizClass, quizOption
'Quizclass = rs ("quizLib. quizClass ")
QuizClass = rs ("quizClass ")
Select case quizClass
Case "radio1"
Response. Write ("answer question ")
Case "radio2"
Response. Write ("single answer ")
Case "checkbox"
Response. Write ("multiple choice questions ")
Case "text"
Response. Write ("Blank question ")
End select
%>

'Are you sure you want to delete a record?
<A href = "del. asp? Info_id = <% = rs ("info_id") %> "onclick = return (confirm (" are you sure you want to delete the record <% = rs ("info_id") %>? ")> Delete </a>

'Dynamic display drop-down menu
'If the record set is empty, it will point to the Home Page
'Value is the ID of the table subject.
<Select name = "booktype" class = "button1" id = "booktype" style = "width: 250">
<Option value = all selected> subject </option>
<%
SQL = "SELECT * FROM subject"
Set rsw.conn.exe cute (SQL)
If rs. bof or rs. eof then response. Redirect ("index. asp ")
While not (rs. bof or rs. eof)
Response. Write "<option value =" & rs ("id") & ">" & rs ("subjName") & "</option>"
Rs. movenext
Wend
%>
</Select>

'Get
<Select name = "mem_sex" id = "mem_sex">
<Option value = "male" <% if rs ("mem_sex") = "male" then response. write "selected" %> male </option>
<Option value = "female" <% if rs ("mem_sex") = "female" then response. write "selected" %> female </option>
</Select>
<! -- Restrict text boxes from entering spaces -->
<Script language = "javascript">
Function id_keyup (txtinput)
{
Txtinput. value = txtinput. value. replace (/(^/s *) | (/s * $)/g ,"");
}
</Script>
<Input type = "text" name = "id" onkeyup = "id_keyup (this)">

9. Random background music:
<% Randomize %>
<Bgsound src = "mids/<% = (int (rnd () * 60) + 1) %>. mid" loop = "-1">

You can modify the number to limit the number of calls. Here are 60 calls.

Display of the status bar text. This is simple and practical!
<BASE onmouseover = "window. status = 'Welcome! -My Email: mxsky {at} 126.com '; return true ">

A mini window opened

"Copy code" "Run code 』

<Script language = "javascript">
Function mini_window (page, w, h)
// Open a small window
/*
Page name
W width
H height
*/
{
Var arr = showModalDialog (page, "", "dialogWidth:" + w + "px; dialogHeight:" + h + "px; status: 0; help: 0 ");
}
// Open a small window
</Script>
<Body style = "overflow: scroll; overflow-x: hidden; overflow-y: hidden">
<A style = cursor: hand; onclick = mini_window ('default. asp ', '000000', '000000')> open a new window </a>
</Body>

Title-added Email:
<A href = "mailto: admin@anquan.com.cn? Subject = questions about the examination system "> flashboy </a>

How to make the background transparent when calling iframe
<Iframe src = "transparent.htm" allowtransparency = "true"> </Iframe>
Transparent.htm
<Body style = "background-color: transparent">

Button opens in the original window
<Input type = "button" name = "button2" value = "register" onclick = "location. href = 'HTTP: // www.google.com '">

Button opens in a new window
<Input type = "button" name = "button2" value = "register" onclick = "window. open ('HTTP: // www.google.com ')">

Automatically wrap an English string out of the table width
<Td style = "word-wrap: break-word; word-break: break-all;">

Always carry the framework
<Script language = "JavaScript">
<! --
If (window = top) top. location. href = "frames.htm"; // frames.htm is the frame webpage.
// -->
</Script>

Prevent frame
<Script language = JAVASCRIPT>
<! --
If (top. location! = Self. location) top. location = self. location;
// -->
</SCRIPT>

Webpages cannot be saved
<Noscript> <iframe src = *. html> </iframe> </noscript>

Confirm deletion
<A href = 'javascript: if (confirm ("are you sure you want to delete it? ") Location =" del. asp "'> Delete </a>

Do not scroll bar
Make the vertical bar not:
<Body style = 'overflow: scroll; overflow-y: Den den '>
</Body>
Make the horizontal bar unavailable:
<Body style = 'overflow: scroll; overflow-x: Den den '>
</Body>
Remove both of them? Simpler:
<Body scroll = "no">
</Body>

Move the mouse over to change the color of the table
<Tr onmouseover = "this. bgColor = 'red'" onmouseout = "this. bgColor ='' ">

Right-click shielding
<Body oncontextmenu = "return false;">
Or
<Script language = "JavaScript">
<! --
If (window. Event)
Document. captureEvents (Event. MOUSEUP );
Function nocontextmenu ()
{
Event. cancelBubble = true
Event. returnValue = false;
Return false;
}
Function norightclick (e)
{
If (window. Event)
{
If (e. which = 2 | e. which = 3)
Return false;
}
Else
If (event. button = 2 | event. button = 3)
{
Event. cancelBubble = true
Event. returnValue = false;
Return false;
}
}
Document. oncontextmenu = nocontextmenu; // for IE5 +
Document. onmousedown = norightclick; // for all others
// -->
</Script>

Use regular expressions to force numbers
<Input name = "id2" type = "text" onkeyup = 'this. value = this. value. replace (// D/gi, "") '>

Do not enter Chinese Characters
<Input type = text style = "ime-mode: disabled">

The text box cannot be completed automatically.
<Input autocomplete = off>

The image is grayed out and restored

Regularly jump to other pages
<Meta http-equiv = "refresh" content = "5; URL = http://54caizi.com">

TITLE line feed
<A href = # title = "line 1, line 2, and line 3"> title branch test </a>

Row background color gradient
<Table width = "100%" height = "100%">
<Tr> <td style = "FILTER: progid: DXImageTransform. microsoft. gradient (endColorstr = '# EFF3FF', startColorstr = '#94B2F7', gradientType = '1') "> </td> </tr>
</Table>
Note:
Function gradient from startcolorstr to endcolorstr
GardientType is a fill style. Try it for specific values.

Call other pages
<Object type = "text/x-scriptlet" width = "800" height = "1000" data = "a.htm"> </object>

Common Iframe usage
<Iframe WIDTH = 100% HEIGHT = 240 MARGINWIDTH = 0 MARGINHEIGHT = 0 HSPACE = 0 VSPACE = 0 FRAMEBORDER = 0 allowTransparency = "true" SCROLLING = no SRC = 'cay/blog. asp '> </iframe>

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.