Some common code for ASP beginners

Source: Internet
Author: User
Beginner

1. Access to System time:
<%=now ()%>
2. Access to the IP:
<%=request.servervariables ("Remote_host")%>
3. Access to the system, browser version:
<script>
Window.document.write ("Version:" +navigator.appname+navigator.appversion+ "browser.")
</script>
4. Remove IE Mixing strips:
<bodyscroll= "No" >
<bodystyle= "Overflow-y:hidden" >
5. Go to the website and jump out of the advertisement:
<scriptlanguage= "JavaScript" >
<!--
<!--note change the path to the file-->
window.open (' http://www.XXXXXX.com ', ', ', ', ', ' height=200,width=300,top=0,left=30 ');
-->
</script>
6. Random Number:
<%randomize%>
<%= (int (rnd () *n) +1)%>
N is a number that can be changed
7. Move Up code:
<marqueedirection= "Up" scrolldelay= "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 Web page:
<scriptlanguage= "JavaScript" >
<!--
SetTimeout (' Window.close (); ', 10000);//60 seconds to close
-->
</script>
<palign= "Center" > this page closes automatically after 10 seconds, please note refresh page </p>
9. Random background music:
<%randomize%>
<bgsoundsrc= "mids/<%=" (Int (rnd () *60) +1)%>.mid "loop="-1 ">

Can modify the number, limit the number of calls, I am here 60.
10. Automatically refresh this page:
<script>
<!--

varlimit= "0:10"

if (document.images) {
Varparselimit=limit.split (":")
Parselimit=parselimit[0]*60+parselimit[1]*1
}
Functionbeginrefresh () {
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+ "+cursec+" seconds after the brush this page! "
Else
curtime=cursec+ "Seconds later to brush this page!" "
Window.status=curtime
SetTimeout ("Beginrefresh ()", 1000)
}
}

Window.onload=beginrefresh
File://-->
</script>
11.ACCESS Database connection:
<%
OptionExplicit
Dimstartime,endtime,conn,connstr,db
Startime=timer ()
' Change database name
db= "Data/dvbbs5.mdb"
Setconn=server.createobject ("ADODB.") Connection ")
Connstr= "provider=microsoft.jet.oledb.4.0;datasource=" &server.mappath (db)
' If your server is powered by an older version of Access, use the following connection method
' Connstr= ' Driver={microsoftaccessdriver (*.mdb)};d bq= "&server.mappath (db)
Conn. Openconnstr
Functionclosedatabase
Conn.close
Setconn=nothing
Endfunction
%>
12.SQL Database connection:
<%
OptionExplicit
Dimstartime,endtime,conn,connstr,db
Startime=timer ()
Connstr= "Driver={sqlserver};server=hudenq-n11t33nb;uid=sa;pwd=xsfeihu;database=dvbbs"
Setconn=server.createobject ("ADODB.") Connection ")
Conn. Openconnstr
Functionclosedatabase
Conn.close
Setconn=nothing
Endfunction
%>
13. Open the page code with the keyboard:
<scriptlanguage= "JavaScript" >
Functionctlent (EventObject)
{
if ((event.ctrlkey&&window.event.keycode==13) | | (event.altkey&&window.event.keycode==83))
{
window.open (' url ', ', ', ')
}
}
</script>

This is Ctrl+enter and Alt+s's code. Check the ASCII code of the keyboard and change it.
14. Let the layer not be covered by the control code:
<divz-index:2><object***></object></div># Front
<divz-index:1><object***></object></div># back.
<divid= "Layer2" style= "Position:absolute;top:40;width:400px;height:95px;z-index:2" ><tableheight=100% Width=100%bgcolor= "#ff0000" ><tr><tdheight=100%width=100%></td></tr></table> <iframewidth=0height=0></iframe></div>
<divid= "Layer1" style= "Position:absolute;top:50;width:200px;height:115px;z-index:1" ><iframeheight=100% Width=100%></iframe></div>
15. Dynamic Network Flash Advertising code:
<objectclassid= "clsid27cdb6e-ae6d-11cf-96b8-444553540000" codebase= "width=" 468 "height=" "><paramname" =movievalue= "images/yj16d.swf" ><paramname=qualityvalue=high><embedsrc= "images/dvbanner.swf" quality =highpluginspage= "";;; Type= "Application/x-shockwave-flash" width= "468" height= "></embed></object>"
16.VBS pop-up window Small code:
<scriptlanguage=vbscript>
MsgBox "You haven't registered or landed forum", "0", "Boutique Forum"
location.href= "Login.asp"
</script>
16. Functions to modify file-specific content using the FSO
Functionfsochange (filename,target,string)
Dimobjfso,objcountfile,filetempdata
Setobjfso=server.createobject ("Scripting.FileSystemObject")
Setobjcountfile=objfso.opentextfile (Server.MapPath (filename), 1,true)
Filetempdata=objcountfile.readall
Objcountfile.close
Filetempdata=replace (filetempdata,target,string)
Setobjcountfile=objfso.createtextfile (Server.MapPath (filename), True)
Objcountfile.writefiletempdata
Objcountfile.close
Setobjcountfile=nothing
Setobjfso=nothing
Endfunction
17. Functions to read the contents of a file using the FSO
Functionfsofileread (filename)
Dimobjfso,objcountfile,filetempdata
Setobjfso=server.createobject ("Scripting.FileSystemObject")
Setobjcountfile=objfso.opentextfile (Server.MapPath (filename), 1,true)
Fsofileread=objcountfile.readall

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.