- 在body标签里加上οncοntextmenu=self.event.returnValue=false ;<table border οncοntextmenu=return(false)><td>no</table> 可用于Table
- 取消选取、防止复制:<body onselectstart="return false">
- 不准粘贴 : οnpaste="return false"
- 防止复制:οncοpy="return false;" oncut="return false;"
- IE地址栏前换成自己的图标:<link rel="Shortcut Icon" href="favicon.ico">
- 可以在收藏夹中显示出你的图标:<link rel="Bookmark" href="favicon.ico">
- 关闭输入法 <input style="ime-mode:disabled">
- 永远都会带着框架 :script language="JavaScript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页
// --></script> - 防止被人frame :<SCRIPT LANGUAGE=JAVASCRIPT><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT> - 网页将不能被另存为:<noscript><iframe src=*.html></iframe></noscript>
- 怎样通过asp的手段来检查来访者是否用了代理:<% if Request.ServerVariables("HTTP_X_FORWARDED_FOR")<>"" then
response.write "<font color=#FF0000>您通过了代理服务器,"& _
"真实的IP为"&Request.ServerVariables("HTTP_X_FORWARDED_FOR")
end if
%> - 取得控件的绝对位置://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>
//VBScript
<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> - 光标是停在文本框文字的最后 :<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" οnfοcus="cc()"> - 判断上一页的来源
asp:
request.servervariables("HTTP_REFERER")
javascript:
document.referrer - 最小化、最大化、关闭窗口 :<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=最小化 οnclick=hh1.Click()>
<input type=button value=最大化 οnclick=hh2.Click()>
<input type=button value=关闭 οnclick=hh3.Click()>
本例适用于IE - 网页不会被缓存
HTM网页
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
或者<META HTTP-EQUIV="expires" CONTENT="0">
ASP网页
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.cachecontrol = "no-cache"
PHP网页
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache"); - 获得一个窗口的大小:document.body.clientWidth,document.body.clientHeight
- 怎么判断是否是字符 :if (/[^/x00-/xff]/g.test(s)) alert("含有汉字");
else alert("全是字符"); - TEXTAREA自适应文字行数的多少<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight"> </textarea>
- 日期减去天数等于第二个日期 <script language=Javascript>
function cc(dd,dadd)
{
//可以加上错误处理
var a = new Date(dd)
a = a.valueOf()
a = a - dadd * 24 * 60 * 60 * 1000
a = new Date(a)
alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")
}
cc("12/23/2002",2)
</script> - 选择了哪一个Radio <HTML><script language="vbscript">
function checkme()
for each ob in radio1
if ob.checked then window.alert ob.value
next
end function
</script><BODY>
<INPUT name="radio1" type="radio" value="style" checked>Style
<INPUT name="radio1" type="radio" value="barcode">Barcode
<INPUT type="button" value="check" οnclick="checkme()">
</BODY></HTML> - 获得本页url的request.servervariables("")集合
Response.Write "<TABLE border=1><!-- Table Header --><TR><TD><B>Variables</B></TD><TD><B>Value</B></TD></TR>"
for each ob in Request.ServerVariables
Response.Write "<TR><TD>"&ob&"</TD><TD>"&Request.ServerVariables(ob)&"</TD></TR>"
next
Response.Write "</TABLE>" - 本机ip<%=request.servervariables("remote_addr")%>
服务器名<%=Request.ServerVariables("SERVER_NAME")%>
服务器IP<%=Request.ServerVariables("LOCAL_ADDR")%>
服务器端口<%=Request.ServerVariables("SERVER_PORT")%>
服务器时间<%=now%>
IIS版本<%=Request.ServerVariables"SERVER_SOFTWARE")%>
脚本超时时间<%=Server.ScriptTimeout%>
本文件路径<%=server.mappath(Request.ServerVariables("SCRIPT_NAME"))%>
服务器CPU数量<%=Request.ServerVariables("NUMBER_OF_PROCESSORS")%>
服务器解译引擎<%=ScriptEngine & "/"& ScriptEngineMajorVersion &"."&ScriptEngineMinorVersion&"."& ScriptEngineBuildVersion %>
服务器操作系统<%=Request.ServerVariables("OS")%> - ENTER键可以让光标移到下一个输入框:input οnkeydοwn="if(event.keyCode==13)event.keyCode=9">
- 检测某个网站的链接速度::把如下代码加入<body>区域中:
<script language=Javascript>
tim=1
setInterval("tim++",100)
b=1
var autourl=new Array()
autourl[1]="www.njcatv.net"
autourl[2]="javacool.3322.net"
autourl[3]="www.sina.com.cn"
autourl[4]="www.nuaa.edu.cn"
autourl[5]="www.cctv.com"
function butt(){
document.write("<form name=autof>")
for(var i=1;i<autourl.length;i++)
document.write("<input type=text name=txt"+i+" size=10 value=测试中……> =》<input type=text name=url"+i+" size=40> =》<input type=button value=GO οnclick=window.open(this.form.url"+i+".value)><br/>")
document.write("<input type=submit value=刷新></form>")
}
butt()
function auto(url){
document.forms[0]["url"+b].value=url
if(tim>200)
{document.forms[0]["txt"+b].value="链接超时"}
else
{document.forms[0]["txt"+b].value="时间"+tim/10+"秒"}
b++
}
function run(){for(var i=1;i<autourl.length;i++)document.write("<img src=http://"+autourl[i]+"/"+Math.random()+" width=1 height=1 οnerrοr=auto('http://"+autourl[i]+"')>")}
run()</script> - 各种样式的光标 :auto :标准光标
default :标准箭头
hand :手形光标
wait :等待光标
text :I形光标
vertical-text :水平I形光标
no-drop :不可拖动光标
not-allowed :无效光标
help :?帮助光标
all-scroll :三角方向标
move :移动标
crosshair :十字标
e-resize
n-resize
nw-resize
w-resize
s-resize
se-resize
sw-resize - <script language=javascript>
function KeyDown(){
if ((window.event.altKey)&&
((window.event.keyCode==37)|| //屏蔽 Alt+ 方向键 ←
(window.event.keyCode==39))){ //屏蔽 Alt+ 方向键 →
alert("不准你使用ALT+方向键前进或后退网页!");
event.returnValue=false;
}
if ((event.keyCode==8)|| //屏蔽退格删除键
(event.keyCode==116)){ //屏蔽 F5 刷新键
event.keyCode=0;
event.returnValue=false;
}
if ((event.ctrlKey)&&(event.keyCode==78)){ //屏蔽 Ctrl+n
event.returnValue=false;
}
if ((event.shiftKey)&&(event.keyCode==121)){ //屏蔽 shift+F10
event.returnValue=false;
}
if (event.keyCode==122){ //屏蔽 F11
event.returnValue=false;
}
}
只要知道keyCode即可屏蔽所有功能键 - 判断浏览器的类型
window.navigator.appName - 判断ie的版本
window.navigator.appVersion - 判断客户端的分辨率
window.screen.height; window.screen.width - email的判断。
function ismail(mail)
{
return(new RegExp(/^/w+((-/w+)|(/./w+))*/@[A-Za-z0-9]+((/.|-)[A-Za-z0-9]+)*/.[A-Za-z0-9]+$/).test(mail));
} - 身份证的验证
function isIdCardNo(num)
{
if (isNaN(num)) {alert("输入的不是数字!"); return false;}
var len = num.length, re;
if (len == 15)
re = new RegExp(/^(/d{6})()?(/d{2})(/d{2})(/d{2})(/d{3})$/);
else if (len == 18)
re = new RegExp(/^(/d{6})()?(/d{4})(/d{2})(/d{2})(/d{3})(/d)$/);
else {alert("输入的数字位数不对!"); return false;}
var a = num.match(re);
if (a != null)
{
if (len==15)
{
var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);
var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
}
else
{
var D = new Date(a[3]+"/"+a[4]+"/"+a[5]);
var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
}
if (!B) {alert("输入的身份证号 "+ a[0] +" 里出生日期不对!"); return false;}
}
return true;
} - 文件上传过程中判断文件类型
<input type=file οnchange="alert(this.value.match(/^(.*)(/.)(.{1,8})$/)[3])"> - 不断地清空剪贴板:
<body οnlοad="setInterval('clipboardData.setData(/'Text/',/'/')',100)" - 先复制一样东西,或者文本或者图片
if(clipboardData.getData("Text")||clipboardData.getData("HTML")||clipboardData.getData("URL")) - 全屏
1.htm
<html>
<head>
<title>无标题文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body οnlοad="window.open('fullscreen.htm','','fullscreen=1,scroll=no');">
</body>
</html>
fullscreen.htm
<html>
<head>
<title>无标题文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript1.2">
<!--
function opensmallwin(myurl){
var w2=300;//想弹出窗口的宽度
var h2=100;//想弹出窗口的高度
var w3=window.screen.width/2-w2/2;
var h3=window.screen.height/2-h2/2;
window.open(myurl,'small','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=0,width='+ w2 +',height='+ h2 +',left='+ w3 +',top='+ h3 +'');
}
//-->
<!--
function modelesswin(url,mwidth,mheight){
if (document.all&&window.print)
eval('window.showModelessDialog(url,"","help:0;resizable:0;status:0;center:1;scroll:0;dialogWidth:'+mwidth+'px;dialogHeight:'+mheight+'px")')
else
eval('window.open(url,"","width='+mwidth+'px,height='+mheight+'px,resizable=1,scrollbars=1")')
}
//-->
</script>
</head>
<body scroll="no">
<div align="right"><a href="javascript:" οnclick="window.close()">关闭</a> </div>
<p></P>
<div align="right"><a href="javascript:" οnclick="opensmallwin('login.htm')">登录</a> </div>
<p></P>
<div align="center"><a href="javascript:" οnclick="modelesswin('login.htm',300,160)">用模态登录窗口</a> </div>
</body>
</html>
login.htm
<html>
<head>
<title>用户登录</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body {
background-color: #EAEAEA;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 24px;
color: #336699;
}
input.boxline {
width: 100px;
font-family: "Times New Roman", "Times", "serif";
font-size: 9pt;
border: 1px solid #669999;
height: 18px;
}
input.whiteline {
font-size: 12px; border: 1px #999999 solid
}
-->
</style></head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="14" bgcolor="#CCCCCC">
<tr valign="top">
<td width="10%" nowrap align="right"><b>用户名:</b></td>
<td width="90%"><input name="textfield1" type="text" size="25" class="whiteline"></td>
</tr>
<tr valign="top">
<td nowrap align="right"><b>密 码:</b></td>
<td><input name="textfield12" type="password" size="25" class="whiteline"></td>
</tr>
<tr valign="top">
<td> </td>
<td><input type="submit" name="Submit" value="登 录" class="boxline"></td>
</tr>
</table>
</body>
</html>
自动关掉原窗口:
<html>
<head>
<title>无标题文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
</head>
<body οnlοad="window.open('fullscreen.htm','','fullscreen=1,scroll=no');window.opener=null;window.close()">
<input type=button value=关闭 οnclick="window.opener=null;window.close()">
<!-- IE5.5+ 不会有弹出提示 -->
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT>
<input type=button value=关闭窗口 οnclick=document.all.WebBrowser.ExecWB(45,1)>
</body>
</html>
关键是在onload事件中加入:
window.opener=null;window.close() - 两个网页刷新交互的问题
JS处理方法:
a.htm
<a href="b.htm" target=blank>发表留言</a>
<script>
alert("wwwwwwwwwwwwwwwwwwwwwwwwww");
</script>
b.htm
<script language="javascript">
//window.opener.location.reload();刷新父窗口
//window.opener.location="2.htm"//重定向父窗口到2.htm页
function closewindow()
{
window.opener.location.reload();
self.close();
window.opener.document.write("sssssssssssssssssss");
}
</script>
<a href="b.htm" target=blank οnclick="closewindow();">关闭</a>
后台处理方法:
private btnForSubmit(Object sender,EventArgs e)
{
.............
Response.Write("<script>window.opener.document.execCommand('refresh');window.opener='';window.close();</script>");
//string str="<script>window.opener.document.execCommand('refresh');window.opener='';window.close();</script>";
//this.RegisterStartupScript("mycode",str);
常用Javascript
最新推荐文章于 2024-10-12 10:41:56 发布