1、无提示关闭窗口
<input type="button" onClick="window.opener = '';window.close();" value="IE6最简单的无提示关闭窗口" >
2、防止被人iframe
if (top.location != self.location)
{
top.location.href="http://www.34do.net";
}
3、判断一个对象存在不存在
document.all("a")==null(不存在)
4、弹出子窗口
window.open ('default.asp', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')
5、打开模态窗口
window.showModalDialog('default.asp',window,'help: No; resizable: No; status: No;scrollbars:No;center: Yes;dialogWidth:width;dialogHeight:height;')
6、弹出的子窗口刷新父窗口
window.opener.opener=null;
window.opener.location.reload();
7、模态窗口刷新父窗口
window.parent.dialogArguments.document.execCommand('Refresh');
8、一个js文件包含另外一个js文件
document.write('<script src="/b_trade/public/new/public.js"><//script>');
9、让文字竖着写
<td style="Writing-mode:tb-rl;">佛罗伦</td>
10、iframe引用自己
window.parent.document.getElementById("iframe_dg")
这样在iframe文件里就可以操作它自己,比如:window.parent.document.getElementById("iframe_dg").height=200
11、根据内容自动调整iframe高度
function autoSetiframeSize()
{
var obj=self.parent.parent.document.all[self.name];
if(obj!=null)
{
self.parent.parent.document.all[self.name].style.pixelHeight=self.document.body.scrollHeight+5;
}
}
必须定义iframe的name属性
<iframe id="iframe1" name="iframe1" align="center" frameborder="0" width="100%" height="250" scrolling="no" src="a.asp"></iframe>
将a.asp的<body>修改为:
<body οnlοad="autoSetiframeSize()">
12、为单元格添加渐变色效果(ie支持,firefox不支持)
.bg3
{
FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr=#842B00, EndColorStr=#FFFFFF);
}
13、定时执行任务
规定一项任务在一定时间内执行:delayID=setTimeout(vCode, iMilliSeconds),在需要的时候,可以强制停止该任务:clearTimeout(delayID)
14、自动选中复制
<span οnmοuseοver="var obj=document.body.createTextRange();obj.moveToElementText(this);obj.select();obj.execCommand('Copy')" οnclick="var obj=document.body.createTextRange();obj.moveToElementText(this);obj.select();obj.execCommand('Copy')" >选中我并复制我</span>
15、产生随机数
VB的Rnd函数产生的随机数范围为0-1。假如要从(min,max)这个范围内随机抽取一个数,具体公式如下: 随机数 = (max - min) * Rnd() + min,min和max可以是任意整数,只是min<max。
16、页面宽高
网页可见区域宽:document.body.offsetWidth (包括边线的宽)
网页可见区域高:document.body.offsetHeight (包括边线的宽)
网页正文全文宽:document.body.scrollWidth
网页正文全文高:document.body.scrollHeight
网页被卷去的高:document.body.scrollTop
网页被卷去的左:document.body.scrollLeft
网页正文部分上:window.screenTop
网页正文部分左:window.screenLeft
屏幕分辨率的高:window.screen.height
屏幕分辨率的宽:window.screen.width
屏幕可用工作区高度:window.screen.availHeight
屏幕可用工作区宽度:window.screen.availWidthvar t="";
t+="/n网页可见区域宽:"+ document.body.clientWidth;
t+="/n网页可见区域高:"+ document.body.clientHeight;
t+="/n网页可见区域宽:"+ document.body.offsetWidth;// (包括边线的宽)
t+="/n网页可见区域高:"+ document.body.offsetHeight;// (包括边线的宽)
t+="/n网页正文全文宽:"+ document.body.scrollWidth;
t+="/n网页正文全文高:"+ document.body.scrollHeight;
t+="/n网页被卷去的高:"+ document.body.scrollTop;
t+="/n网页被卷去的左:"+ document.body.scrollLeft;
t+="/n网页正文部分上:"+ window.screenTop;
t+="/n网页正文部分左:"+ window.screenLeft;
t+="/n屏幕分辨率的高:"+ window.screen.height;
t+="/n屏幕分辨率的宽:"+ window.screen.width;
t+="/n屏幕可用工作区高度:"+ window.screen.availHeight;
t+="/n屏幕可用工作区宽度:"+ window.screen.availWidth;
t+="/n鼠标X位置:"+ event.clientX;
t+="/n鼠标Y位置:"+ event.clientY;
注意,在使用了W3C标准的网页中,document.body.scrollTop和document.body.scrollLeft会失效,这时要用 document.documentElement.scrollTop 和document.documentElement.scrollLeft。
17.示例showMessage()
Code
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function getTopPos(inputObj)
{
var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
return returnValue ;
}
function getleftPos(inputObj)
{
var returnValue = inputObj.offsetLeft;
while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
return returnValue;
}
function ShowMsg(item,s)
{
//alert(left+top);
var it=document.getElementById("DivShowMsg");
var topPadd=5;
it.style.display='block';
it.innerHTML=s;
it.style.zIndex = 1000;
it.style.left=getleftPos(item)+'px';
it.style.top=topPadd+getTopPos(item)+'px';
}
function CloseMsg()
{
var it=document.getElementById("DivShowMsg");
it.style.display='none';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
密 码:<input type="text" width="200px" id="mytext" οnfοcus="ShowMsg(this,'aaaaa')" οnblur="CloseMsg()" />
<div id="DivShowMsg" style="border:solid 1px #ff8400; width:200px;line-height:25px; font-family:'宋体'; font-size:12px;color:#646465; padding:2px 2px 2px 2px; text-align:left; display:none; position:absolute">aaaaaaaaaaaaaaaaadfsdfsdf大法师快递费教案扣篮大赛的发生的</div>
</div>
</form>
</body>
</html>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/madachi/archive/2009/03/03/3953736.aspx