Some web development code collection

Source: Internet
Author: User

Inadvertently rummaging out some previously collected web development on the machineCodeI think it's good. Send it here and try it later.

1. Obtain the system time:
<% = Now () %>

2. Obtain the IP address used for access:
<% = Request. server <I> var </I> iables ("remote_host") %>

3. Obtain the system and browser version:
<I> script </I>
Window.doc ument. Write ("version:" + navigator. appname + navigator. appversion + "browser .")
</<I> script </I>

4. Remove ie hybrid Bars:
<Body scroll = "no">
<Body style = "overflow-Y: hidden">

5. Enter the website and jump out of the advertisement:
<I> script </I> Language = "Java <I> script </I>">
<! --
<! -- Change the file path -->
Window. open (''' http: // www. ******. com <; I >&# </I> 39; '', ''', ''' Height = 200, width = 300, top = 0, Left = 30 '''');
// -->
</<I> script </I>

6. Random Number:
<% Randomize %>
<% = (INT (RND () * n) + 1) %>
N is a changeable variable.

7. Upstream mixed code:
<Marquee direction = "up" scrolldelay = "200" style = "font-size: 9pt; color: # ff0000; line-Height: 150%; font-style: italic; font-weight: bold "scrollamount =" 2 "width =" 206 "Height =" 207 "bgcolor =" # FFFF00 "> hhhhhhhhhhhhhhhhhhh </marquee>

8. automatically close the webpage:
<I> script </I> Language = "Java <I> script </I>">
<! --
SetTimeout (''' window. Close (); ''', 10000); // close after 60 seconds
// -->
</<I> script </I>
<P align = "center"> This page is automatically closed 10 seconds later. Please refresh the page. </P>

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.

10. Automatically refresh this page:
<I> script </I>
<! --

<I> var </I> Limit = "0: 10"

If (document. Images ){
<I> var </I> parselimit = limit. Split (":")
Parselimit = parselimit [0] * 60 + parselimit [1] * 1
}
<I> function </I> beginrefresh (){
If (! Document. Images)
Return
If (parselimit = 1)
Window. Location. Reload ()
Else {
Parselimit-= 1
Curmin = math. Floor (parselimit/60)
Cursec = parselimit % 60
If (curmin! = 0)
Curtime = curmin + "Minute" + cursec + "second to refresh this page! "
Else
Curtime = cursec + "refresh this page in seconds! "
Window. Status = curtime
SetTimeout ("Maid ()", 1000)
}
}

Window. <I> onload </I> = beginrefresh
<I> file: </I> // -->
</<I> script </I>

11. Access database connection:
<%
Option explicit
Dim startime, endtime, Conn, connstr, DB
Startime = timer ()
''Change Database Name
DB = "Data/dvbbs5.mdb"
Set conn = server. Createobject ("ADODB. Connection ")
Connstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & server. mappath (db)
''If your server uses an older version of the access driver, use the following connection method:
''Connstr = "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & server. mappath (db)
Conn. Open connstr
<I> function </I> closedatabase
Conn. Close
Set conn = nothing
End <I> function </I>
%>

12. SQL database connection:
<%
Option explicit
Dim startime, endtime, Conn, connstr, DB
Startime = timer ()
Connstr = "driver = {SQL Server}; server = HUDENQ-N11T33NB; uid = sa; Pwd = xsfeihu; database = dvbbs"
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open connstr
<I> function </I> closedatabase
Conn. Close
Set conn = nothing
End <I> function </I>
%>

13. Use the keyboard to open the webpage code:
<I> script </I> Language = "Java <I> script </I>">
<I> function </I> ctlent (eventobject)
{
If (event. ctrlkey & window. event. keycode = 13) │ (event. altkey & window. event. keycode = 83 ))
{
Window. Open (''url '','''','''')
}
}
</<I> script </I>

Here is the code for Ctrl + enter and ALT + S. Just check the ASCII code of the keyboard and change it.

14. code to prevent the layer from being overwritten by controls:

# front
#
IFRAME
IFRAME Height = 100% width = 100%> IFRAME

width = 0 Height = 0> IFRAME

15. flash advertisement code:

16. small code in the vbs pop-up window:
script Language = VB script
msgbox "You have not registered or logged on to the Forum ", "0", "Boutique Forum"
location. href = "login. ASP "
script
16. function for modifying specific file content using FSO
function fsochange (filename, target, string)
dim objfso, objcountfile, filetempdata
set objfso = server. createobject (" script ing. fileSystemObject ")
set objcountfile = objfso. opentextfile (server. mappath (filename), 1, true)
filetempdata = objcountfile. readall
objcountfile. close
filetempdata = Replace (filetempdata, target, string)
set objcountfile = objfso. createtextfile (server. mappath (filename), true)
objcountfile. write filetempdata
objcountfile. close
set objcountfile = nothing
set objfso = nothing
end function

17. function for reading file content using FSO
function fsofileread (filename)
dim objfso, objcountfile, filetempdata
set objfso = server. createobject (" script ing. fileSystemObject ")
set objcountfile = objfso. opentextfile (server. mappath (filename), 1, true)
fsofileread = objcountfile. readall
objcountfile. close
set objcountfile = nothing
set objfso = nothing
end function

18. function for reading a row of a file using FSO
function fsolinedit (filename, linenum)
If linenum <1 then exit function
dim FSO, F, temparray, tempcnt
set FSO = server. createobject (" script ing. fileSystemObject ")
if not FSO. fileexists (server. mappath (filename) Then exit function
set f = FSO. opentextfile (server. mappath (filename), 1)
if not F. atendofstream then
tempcnt = f. readall
F. close
set f = nothing
temparray = Split (tempcnt, CHR (13) & CHR (10)
If linenum> ubound (temparray) + 1 then
exit function
else
fsolinedit = temparray (lineNum-1)
end if
end function

19. function for writing a row of a file using FSO
function fsolinewrite (filename, linenum, linecontent)
If linenum <1 then exit function
dim FSO, F, temparray, tempcnt
set FSO = server. createobject (" script ing. fileSystemObject ")
if not FSO. fileexists (server. mappath (filename) Then exit function
set f = FSO. opentextfile (server. mappath (filename), 1)
if not F. atendofstream then
tempcnt = f. readall
F. close
temparray = Split (tempcnt, CHR (13) & CHR (10)
If linenum> ubound (temparray) + 1 then
exit function
else
temparray (lineNum-1) = linecontent
end if
tempcnt = join (temparray, CHR (13) & CHR (10)
set f = FSO. createtextfile (server. mappath (filename), true)
F. write tempcnt
end if
F. close
set f = nothing
end function

20. use the FSO function to add a new row of the file
function fsoappline (filename, linecontent)
dim FSO, F
set FSO = server. createobject (" script ing. fileSystemObject ")
if not FSO. fileexists (server. mappath (filename) Then exit function
set f = FSO. opentextfile (server. mappath (filename), 8, 1)
F. write CHR (13) & CHR (10) & linecontent
F. close
set f = nothing
end function

21. function for reading the last row of a file
function fsolastline (filename)
dim FSO, F, temparray, tempcnt
set FSO = server. createobject (" script ing. fileSystemObject ")
if not FSO. fileexists (server. mappath (filename) Then exit function
set f = FSO. opentextfile (server. mappath (filename), 1)
if not F. atendofstream then
tempcnt = f. readall
F. close
set f = nothing
temparray = Split (tempcnt, CHR (13) & CHR (10)
fsolastline = temparray (ubound (temparray ))
end if
end function
Use FSO to obtain information about BMP, JPG, PNG, and GIF files (size, width, and height)
<%
'': BMP, GIF, JPG and PNG:

'': This function gets a specified number of bytes from any :::
'': file, starting at the offset (base 1):
'': :::::
'': passed ::::
'': flnm => filespec of file to read :::< br>'': offset => offset at which to start reading :::
'': bytes => How many bytes to read :::< br>'' ::::::::
''::::: :::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::< br> function getbytes (flnm, offset, bytes)
dim objfso
dim objftemp
dim objtextstream
dim lngsize
on error resume next
set objfso = Createobject (" script ing. fileSystemObject ")

''first, we get the filesize
set objftemp = objfso. getFile (flnm)
lngsize = objftemp. size
set objftemp = nothing
fsoforreading = 1
set objtextstream = objfso. opentextfile (flnm, fsoforreading)
If Offset> 0 then
strbuff = objtextstream. read (offset-1)
end if
If bytes =-1 then'' get all!
getbytes = objtextstream. read (lngsize) ''readall
else
getbytes = objtextstream. read (bytes)
end if
objtextstream. close
set objtextstream = nothing
set objfso = nothing
end function

'':::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
''::::::
'': <I> function </I> S to convert two bytes to a numeric value (long ):::
'': (Both little-Endian and big-Endian ):::
''::::::
'':::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
<I> function </I> lngconvert (strtemp)
Lngconvert = clng (ASC (left (strtemp, 1) + (ASC (right (strtemp, 1) * 256 )))
End <I> function </I>
<I> function </I> lngconvert2 (strtemp)
Lngconvert2 = clng (ASC (right (strtemp, 1) + (ASC (left (strtemp, 1) * 256 )))
End <I> function </I>

'':::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
''::::::
'': This <I> function </I> does most of the real work. It will attempt :::
'': To read any file, regardless of the extension, and will :::
'': Identify if it is a graphical image .:::
''::::::
'': Passed ::::
'': Flnm => filespec of file to read :::
'': Width => width of image :::
'': Height => height of image :::
'': Depth => color depth (in number of colors ):::
'': Strimagetype => type of image (e.g. GIF, BMP, etc .):::
''::::::
'':::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
<I> function </I> gfxspex (flnm, width, height, depth, strimagetype)
Dim strpng
Dim strgif
Dim strbmp
Dim strtype
Strtype = ""
Strimagetype = "(unknown )"
Gfxspex = false
Strpng = CHR (1, 137) & CHR (80) & CHR (78)
Strgif = "GIF"
Strbmp = CHR (66) & CHR (77)
Strtype = getbytes (flnm, 0, 3)
If strtype = strgif then'' is gif
Strimagetype = "GIF"
Width = lngconvert (getbytes (flnm, 7, 2 ))
Height = lngconvert (getbytes (flnm, 9, 2 ))
Depth = 2 ^ (ASC (getbytes (flnm, 11, 1) and 7) + 1)
Gfxspex = true
Elseif left (strtype, 2) = strbmp then ''is BMP
Strimagetype = "BMP"
Width = lngconvert (getbytes (flnm, 19, 2 ))
Height = lngconvert (getbytes (flnm, 23, 2 ))
Depth = 2 ^ (ASC (getbytes (flnm, 29, 1 )))
Gfxspex = true
Elseif strtype = strpng then ''is PNG
Strimagetype = "PNG"
Width = lngconvert2 (getbytes (flnm, 19, 2 ))
Height = lngconvert2 (getbytes (flnm, 23, 2 ))
Depth = getbytes (flnm, 25, 2)
Select case ASC (right (depth, 1 ))
Case 0
Depth = 2 ^ (ASC (left (depth, 1 )))
Gfxspex = true
Case 2
Depth = 2 ^ (ASC (left (depth, 1) * 3)
Gfxspex = true
Case 3
Depth = 2 ^ (ASC (left (depth, 1) ''8
Gfxspex = true
Case 4
Depth = 2 ^ (ASC (left (depth, 1) * 2)
Gfxspex = true
Case 6
Depth = 2 ^ (ASC (left (depth, 1) * 4)
Gfxspex = true
Case else
Depth =-1
End select

Else
Strbuff = getbytes (flnm, 0,-1) ''get all bytes from File
Lngsize = Len (strbuff)
Flgfound = 0
Strtarget = CHR (255) & CHR (216) & CHR (255)
Flgfound = instr (strbuff, strtarget)
If flgfound = 0 then
Exit <I> function </I>
End if
Strimagetype = "jpg"
Lngpos = flgfound + 2
Exitloop = false
Do While exitloop = false and lngpos <lngsize

Do While ASC (mid (strbuff, lngpos, 1) = 255 and lngpos <lngsize
Lngpos = lngpos + 1
Loop
If ASC (mid (strbuff, lngpos, 1) <192 or ASC (mid (strbuff, lngpos, 1)> 195 then
Lngmarkersize = lngconvert2 (mid (strbuff, lngpos + 1, 2 ))
Lngpos = lngpos + lngmarkersize + 1
Else
Exitloop = true
End if
Loop
''
If exitloop = false then
Width =-1
Height =-1
Depth =-1
Else
Height = lngconvert2 (mid (strbuff, lngpos + 4, 2 ))
Width = lngconvert2 (mid (strbuff, lngpos + 6, 2 ))
Depth = 2 ^ (ASC (mid (strbuff, lngpos + 8, 1) * 8)
Gfxspex = true
End if

End if
End <I> function </I>

'':::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::
'': Test harness :::
'':::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::

''to test, we ''ll just try to show all files with. GIF extension in the root of C:
set objfso = Createobject (" script ing. fileSystemObject ")
set objf = objfso. getfolder ("C: \")
set objfc = objf. files
response. write "







" for each F1 in objfc If instr (ucase (f1.name ), ". GIF ") Then response. write " " end if next response. write "
" & f1.name & " " & f1.datecreated & " " & f1.size & " "
If gfxspex (f1.path, w, h, C, strtype) = true then
response. write W & "X" & H & "& C &" Colors "
else
response. write ""
end if
response. write "
"
set objfc = nothing
set objf = nothing
set objfso = nothing

%>
22. Click Back to the Code on the previous page:
<Form>
<P> <input type = "button" value = "back to previous step" <I> onclick </I> = "history. Back (-1)"> </P>
</Form>

23. Click to refresh the Code:
<Form>
<P> <input type = "button" value = "Refresh button 1" <I> onclick </I> = "reloadbutton ()"> </P>
</Form>
<I> script </I> Language = "Java <I> script </I>"> <! --
<I> function </I> reloadbutton () {location. href = "allbutton.htm ";}
// --> </<I> script </I>

24. Click Refresh Code 2:
<Form>
<P> <input type = "button" value = "Refresh button 2" <I> onclick </I> = "history. Go (0)"> </P>
</Form>

<Form>
<P> <input type = "button" value = "open a website" <I> onclick </I> = "homebutton ()"> </P>
</Form>
<I> script </I> Language = "Java <I> script </I>"> <! --
<I> function </I> homebutton () {location. href = "http://nettrain.126.com ";;;;;}
// --> </<I> script </I>

25. The code in the pop-up warning box is as follows:
<Form>
<P> <input type = "button" value = "pop-up warning box" <I> onclick </I> = "alertbutton ()"> </P>
</Form>
<I> script </I> Language = "Java <I> script </I>"> <! --
<I> function </I> alertbutton () {window. Alert ("coming soon! ");}
// --> </<I> script </I>

26. Status Bar Information
<Form>
<P> <input type = "button" value = "status bar information" <I> onclick </I> = "statusbutton ()"> </P>
</Form>
<I> script </I> Language = "Java <I> script </I>"> <! --
<I> function </I> statusbutton () {window. Status = "coming soon! ";}
// --> </<I> script </I>

27. Background Color Conversion
<Form>
<P> <input type = "button" value = "" <I> onclick </I> = "bgbutton ()"> </P>
</Form>
<I> script </I> <I> function </I> bgbutton (){
If (document. bgcolor = ''# 00ffff '')
{Document. bgcolor = ''# ffff '';}
Else {document. bgcolor = ''# 00ffff '';}
}
</<I> script </I>

28. click Open new window


onclick =" newwindow () ">



script Language =" Java script "> function newwindow () {window. open ("http://www.mcmx.com";, "", "Height = 240, width = 340, status = No, location = No, toolbar = No, directories = No, menubar = No ") ;}< br> // --> script
29. paging code:
<% ''' Program file name: pages. asp %>
<% ''' contains the ADO constant table file adovbs. INC, which can be copied from the "\ Program Files \ common files \ System \ Ado" directory. %>

<% ''' * establishes a database connection. Here is the oracle8.05 database.
set conn = server. createobject ("ADODB. connection ")
Conn. open "provider = msdaora.1; Data Source = yoursrcname; user id = youruserid; Password = yourpassword;"

Set rs = server. Createobject ("ADODB. recordset") ''' Create A recordset object
Rs. cursorlocation = aduseclient ''' sets the record set pointer attribute
''' * Sets the total number of records on one page, which can be adjusted as needed.
Rs. pagesize = 10

''' * Set the query statement
Strsql = "select ID, name, address, phone number from Address Book order by ID"
Rs. Open strsql, Conn, adopenstatic, adlockreadonly, ad1_text
%>
<HTML>
<Head>
<Title> paging example </title>
<I> script </I>

Automatically refresh code on the webpage
<Meta http-equiv = "refresh" content = "10">
<Meta http-equiv = "refresh" content = "seconds; url = redirected file or address">
Change 10 to wantAutomatic Webpage refresh.

For example
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Meta http-equiv = "refresh" content = "10">
<Title> brush... </title>

Automatic Webpage refresh, A solution that does not generate a click
Do not use the refresh attribute in the meta tag to refresh the page. This must be a sound. You just need to add this sentence.

....

....

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.