您好,在这里您可以咨询:域名、空间、邮局、网站制作费用等相关问题。 客服工作人员
您好,在这里您可以咨询:域名、空间、邮局、网站制作售后服务等相关问题。 售后工作人员
您好,技术问题一一为您解答。 技术工作人员

     网站建设
定制建站 CYWEB.CN
专业策划 CYWEB.CN
建站流程 CYWEB.CN
建站售后 CYWEB.CN
SEO优化 CYWEB.CN
网站登录 CYWEB.CN
网络营销 CYWEB.CN
我的客户 CYWEB.CN
成功案例 CYWEB.CN
建站合同 CYWEB.CN
制作需求 CYWEB.CN

     新闻中心
公司新闻 CYWEB.CN
 
技术 CYWEB.CN
 
客服 CYWEB.CN
公司公告 CYWEB.CN
破解补丁 CYWEB.CN


常用的ASP代码
发布&更新:2010-5-27 浏览次数:11789 下载地址:点击下载 问题反馈:报告Bug

1.获得系统时间:
<%=now()%>

2.取得来访用的IP:
<%=request.serverVariables("remote_host")%>

3.获得系统,浏览器版本:
<script>
window.document.write("版本:"+navigator.appName+navigator.appVersion+" browser.")
</script>

4.去除IE混动条:
<body scroll="no">
<body style="overflow-y:hidden">

5.进入网站,跳出广告:
<script language="JavaScript">
<!--
<!-- 注意更改文件所在路径-->
window.open(''http://www.XXXXXX.com'','''',''height=200,width=300,top=0,left=30'');
// -->
</script>

6.随机数:
<%randomize%>
<%=(int(rnd()*n)+1)%>
N为可改变数

7.向上混动代码:
<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.自动关闭网页:
<script LANGUAGE="JavaScript">
<!--
setTimeout(''window.close();'', 10000); //60秒后关闭
// -->
</script>
<p align="center">本页10秒后自动关闭,请注意刷新页面</p>

9.随机背景音乐:
<%randomize%>
<bgsound src="mids/<%=(int(rnd()*60)+1)%>.mid" loop="-1">
可以修改数字,限制调用个数,我这里是60个.

10.自动刷新本页面:
<script>
<!--

var limit="0:10"

if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function 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+"分"+cursec+"秒后重刷本页!"
else
curtime=cursec+"秒后重刷本页!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}

window.onload=beginrefresh
file://-->
</script>

11.用键盘打开网页代码:
<script language="javascript">
function ctlent(eventobject)
{
if((event.ctrlKey && window.event.keyCode==13)||(event.altKey && window.event.keyCode==83))
{
window.open('网址','','')
}
}
</script>
这里是Ctrl+Enter和Alt+S的代码 自己查下键盘的ASCII码再换就行

12.让层不被控件复盖代码:
<div z-Index:2><object xxx></object></div> # 前面
<div z-Index:1><object xxx></object></div> # 后面
<div id="Layer2" style="position:absolute; top:40;width:400px; height:95px;z-index:2"><table height=100% width=100% bgcolor="#ff0000"><tr><td height=100% width=100%></td></tr></table><iframe width=0 height=0></iframe></div>
<div id="Layer1" style="position:absolute; top:50;width:200px; height:115px;z-index:1"><iframe height=100% width=100%></iframe></div>

13.动网FLASH广告代码:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="468" height="60"><param name=movie value="images/yj16d.swf"><param name=quality value=high><embed src="images/dvbanner.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";; type="application/x-shockwave-flash" width="468" height="60"></embed></object>

14.VBS弹出窗口小代码:
<script language=vbscript>
msgbox"你还没有注册或登陆论坛","0","精品论坛"
location.href = "login.asp"
</script>

15.文本提交自动分行
text=replace(text,chr(10),"<br>")
text=replace(text,chr(13),"<br>")

16.关闭子窗口时刷新父窗口
在子窗口
<script language="javascript">
window.opener.location="父窗口页面"
window.close()
</script>

17.关闭子窗口时刷新父窗口
在子窗口 代码是:
<script language="JavaScript">
<!--
self.opener.location.reload();
window.close()
-->
</script>

----特效字------------------------------------------------------
<span style="COLOR: #000088; FILTER: glow(color=white,strength=1) shadow(color=dddddd,direction=130); LINE-HEIGHT: 23pt; POSITION: relative; WIDTH: 100%"> *** </span>

----清空INPUT且选定---------------------------------------------
onClick="Javascript:this.value=''" onFocus="this.select()" onMouseOver="this.focus()"

----全屏显示页面--------------------------------------------
<script language="javascript">
history.back();
chatroom=window.open("chat.asp","chatroom","toolbar=no,status=no,resizable=yes")
chatroom.moveTo(0,0);
chatroom.resizeTo(screen.availWidth,screen.availHeight);
chatroom.outerWidth=screen.availWidth;
chatroom.outerHeight=screen.availHeight;
</script>

------定时关闭窗口------------------------------------------
<script language="JavaScript">
var tid=null;tid=setTimeout('window.close()',300000);
</script>

------右键屏蔽----------------------------------------------
<body oncontextmenu=self.event.returnValue=false>
------Boom!Boom!页------------------------------------------
<script language="JavaScript">while (true){ window.open("bomb.htm","","fullscreen=yes,Status=no,scrollbars=no,resizable=no");}</script>

---------图片重新设置按钮---------------------------------------
<script language="jscript">
function myreset()
{ document.login.reset();
document.login.focus();}
</script>
<img src="image/reclear.gif" width="69" height="20" style="cursor:hand" onfocus="this.blur()" onclick="myreset()"

1.将彻底屏蔽鼠标右键
oncontextmenu="window.event.returnValue=false"
<table border oncontextmenu=return(false)><td>no</table>

2. 取消选取、防止复制<body onselectstart="return false">

3. 不准粘贴 onpaste="return false"

4. 防止复制 oncopy="return false;" oncut="return false;"

5.IE地址栏前换成自己的图标 <link rel="Shortcut Icon" href="favicon.ico">

6. 可以在收藏夹中显示出你的图标 <link rel="Bookmark" href="favicon.ico">

7. 关闭输入法 <input style="ime-mode:disabled">

8. 永远都会带着框架

<script language="JavaScript"><!--

if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页

// --></script>

9. 防止被人frame

<SCRIPT LANGUAGE=JAVASCRIPT><!--

if (top.location != self.location)top.location=self.location;

// --></SCRIPT>

10. 网页将不能被另存为 <noscript><iframe src=*.html></iframe></noscript>

11. <input type=button value=查看网页源代码

onclick="window.location = 'view-source:'+ 'http://www.csdn.net/'";>

12. 怎样通过asp的手段来检查来访者是否用了代理

<% if Request.ServerVariables("HTTP_X_FORWARDED_FOR")<>"" then

response.write "<font color=#FF0000>您通过了代理服务器,"& _

"真实的IP为"&Request.ServerVariables("HTTP_X_FORWARDED_FOR")

end if

%>

13. 取得控件的绝对位置

//Javascript

<script language="Javascript">

function getIE(e){

var t=e.offsetTop;

var l=e.offsetLeft;

while(e=e.offsetParent){

t+=e.offsetTop;

l+=e.offsetLeft;

}

alert("top="+t+"\nleft="+l);

}

</script>

第二小节

<script language="VBScript"><!--

function getIE()

dim t,l,a,b

set a=document.all.img1

t=document.all.img1.offsetTop

l=document.all.img1.offsetLeft

while a.tagName<>"BODY"

set a = a.offsetParent

t=t+a.offsetTop

l=l+a.offsetLeft

wend

msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"

end function

--></script>

14. 光标是停在文本框文字的最后

<script language="javascript">

function cc()

{

var e = event.srcElement;

var r =e.createTextRange();

r.moveStart('character',e.value.length);

r.collapse(true);

r.select();

}

</script>

<input type=text name=text1 value="123" onfocus="cc()">

15. 判断上一页的来源

asp:

request.servervariables("HTTP_REFERER")

javascript:

document.referrer

16. 最小化、最大化、关闭窗口

<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">

<param name="Command" value="Minimize"></object>

<object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">

<param name="Command" value="Maximize"></object>

<OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">

<PARAM NAME="Command" VALUE="Close"></OBJECT>

<input type=button value=最小化 onclick=hh1.Click()>

<input type=button value=最大化 onclick=hh2.Click()>

<input type=button value=关闭 onclick=hh3.Click()>

本例适用于IE

第三小节

将你的网站设为浏览器的首页
只要在页面适当位置加入如下语句,并将“http://www.sujiatun.com/dvbbs/index.htm”替换为你的网址.
<a href="#" onclick="this.style.behavior='url(#default #homepage)';this.setHomePage('http://www.sujiatun.com/dvbbs/index.htm);">将本站设为首页</a>

将你的网站添加到收藏夹
<a href="javascript:window.external.Addfavorite('http://www.sujiatun.com/dvbbs/index.htm','网站名称')">将本站添加到收藏夹</a>

将你的网站添加到频道
首先, 你要制作自己的频道文件, 然后在网页中加入以下语句, 并将“http://www.sujiatun.com/dvbbs/index.htm”替换为你的频道文件的位置.
<a href="javascript:window.external.addChannel('http://www.sujiatun.com/dvbbs/index.htm')">将本站加入你的频道中</a>

查看上一页/下一页
在页面适当位置加入以下语句, 可以进行页面的切换.
<a href="javascript:history.back()">上一页</a>
<a href="javascript:history.forward()">下一页</a>

定时转向页面
在页面<head>内加入以下语句, 并将“http://www.sujiatun.com/dvbbs/index.htm”替换为要转向的网址或主页.
<meta http-equiv="refresh" content="5;url=http://www.sujiatun.com/dvbbs/index.htm">
其中,content="5;中的5为停顿时间(5秒).

窗口的打开/关闭
在页面<head>内加入以下语句, 并将“http://www.sujiatun.com/dvbbs/index.htm”替换为要打开的网址或主页. 打开一个页面的同时弹出一窗口, 并在一分钟后自动关闭.
<script language="javascript">
var newWin=***********("http://www.sujiatun.com/dvbbs/index.htm";,"NEWWIN","status=no,toolbar=no,scrollbars=no,location=no ,menu=no,resizable=no,width=400,height=300")
if (newWin){
setTimeout('newWin.close();', 60000)
}
</script>
其中,('newWin.close();', 60000)中的60000为等候时间(60秒), 单位为毫秒. 若不想自动关闭,请将以下语句删除:
if (newWin){
setTimeout('newWin.close();', 60000)
}

当前窗口的关闭
只要在页面适当位置加入如下语句.
<a href="javascript:window.close()">关闭窗口</a>

在状态栏中显示文字链接的说明
<a href="http://www.suhu.com"; onmouseOver="window.status='优秀的中文搜索引擎';return true;" onmouseOut="window.status='';">搜狐</a>
当鼠标指向搜狐这一链接时,在状态栏中将显示“优秀的中文搜索引擎”信息,鼠标移走,状态栏中的信息清空。

取消文字链接的下划线
在页面<head>内加入以下语句, 所有页面上的文字链接的下划线都取消。当鼠标指向链接时,下划线(红色)才显示(Netscape没有此功能)。
<style TYPE="text/css">
a {text-transform: none; text-decoration: none;}
a:hover {text-decoration: underline; color:red;}
</style>

保护你的页面不被它人放在框架中
为了保护你的页面,请在页面<head>内加入以下语句.
<script language="javascript">
if(self!=top){top.location=self.location;}
</script>

改变行距
在页面<head>内加入以下语句, 所有以<P>开头以</P>结尾的段落,行高将是本身字体大小的150%.
<style type="text/css">
P{line-height:150%}
</style>
在页面如下设置:
<P>这是第一行</P>
<P>这是第二行</P>

文本框自动滚动条
<textarea name=words rows=18 cols=26 style="border:1 solid #000000;background-color:white; font-size:9pt; width:188; overflow:auto" wrap=hard></textarea>

背景全屏
<script language="JavaScript">
function makeIm() {
NS4=(document.layers);
IE4=(document.all);
scaleWidth = true;
scaleHeight = true;
imSRC = "image/200263164930.jpg";
if (NS4) {
origWidth = innerWidth;
origHeight = innerHeight;}
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();}
if (NS4) onresize = reDo;
if (IE4) onresize = reDoIE;
function reDoIE(){
imBG.width = document.body.clientWidth;
imBG.height = document.body.clientHeight;}
winWid = (NS4) ? innerWidth : document.body.clientWidth;
winHgt = (NS4) ? innerHeight : document.body.clientHeight;
imStr = "<div id=elBGim"
+ " style='position:absolute;left:0;top:0;z-index:-1'>"
+ "<img name='imBG' border='0' src="+imSRC;
if (scaleWidth) imStr += " width="+winWid;
if (scaleHeight) imStr += " height="+winHgt;
imStr += "></div>";
document.write(imStr);}
makeIm();
</script>

全选并复制
<FORM name=test><INPUT onclick="javascript:HighlightAll('test.select1')" type=button value=全选并复制><BR><TEXTAREA name=select1 rows=3 cols=46>你好,欢迎您的光临!</TEXTAREA>
</FORM>
<SCRIPT language=Javascript>
<!--

var copytoclip=1

function HighlightAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
if (document.all&&copytoclip==1){
therange=tempval.createTextRange()
therange.execCommand("Copy")
window.status="Contents highlighted and copied to clipboard!"
setTimeout("window.status=''",1800)
}
}
//-->
</SCRIPT>

屏蔽JAVASCRIPT错误
<script language="JavaScript">
<!--
function killErrors(){
return true;
}
window.onerror = killErrors;
-->
</script>



返回 |  顶部 |  建站知识