如何让iframe根据内容适应高度
<iframe src="http://www.baidu.com" onload="this.height = this.document.body.offsetHeight;this.width=this.document.body.offsetWidth;"></iframe>
window.close()怎样使得关闭窗口时,ie不弹出确认对话框
<input type="button" onClick="window.opener='xxx';window.close();" value="IE6最简单的无提示关闭窗口" >
屏蔽右键菜单
非js方法:〈body oncontextmenu=self.event.returnValue=false〉
js方法:
if (window.Event)
document.captureEvents(Event.MOUSEUP);
function nocontextmenu()
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
function norightclick(e)
{
if (window.Event)
{
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
判断分辨率
<script>
alert(screen.width+'*'+screen.height)
</script>
关闭窗口三种办法
方法一:window.close();
通常情况下:window.opener=null;window.close();都是可行的。
所述的情况下,window.close()失效
方法二:
<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
但在通常的网页中,结果是:“仅在HTML帮助中才有此功能”!
方法三:
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2
height=0 width=0></OBJECT>
window.document.all.WebBrowser.ExecWB(45,1);
所述的问题,但有限制,就是要降低IE的安全级别。
只能输入数字正则
<input onKeyUp="value=value.replace(/\D+/g,'')">
只能输入中文正则
<input onKeyUp="value=value.replace(/[ -}]/g,'')">
用回车提交表单
<body onLoad="form.txt.focus()">
<form name="form">
<input name="txt" size="100" value="Mouse点我提交,按Enter也提交" onClick="form.submit()" onKeyDown="if (event.keyCode==13)form.submit()">
</form>
通过层来实现渐淡淡出
<script language="JavaScript1.2">
function makevisible(cur,which){
if (which==0)
cur.filters.alpha.opacity=100
else
cur.filters.alpha.opacity=50
}
</script>
<div style="width:200px;height:200px;filter:alpha(opacity=50);border:1px solid #000;background:#0000FF" onMouseOver="makevisible(this,0)" onMouseOut="makevisible(this,1)">
ywicc.com
</div>
关闭输入法
<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>
取得控件的绝对位置
//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);
}
屏蔽功能键Shift,Alt,Ctrl
<script>
function look(){
if(event.shiftKey)
alert("禁止按Shift键!"); //可以换成ALT CTRL
}
document.onkeydown=look;
</script>
网页不会被缓存
<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">
java 版
// 设置编码方式及缓存;
response.setContentType("text/html; charset=GB2312");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
怎样让表单没有凹凸感
<input type=text style="border:1 solid #000000">
或
<input type=text style="border-left:none; border-right:none; border-top:none; border-bottom: 1 solid #000000"></textarea>
<div><span>&<layer>的区别
<div>(division)用来定义大段的页面元素,会产生转行
<span>用来定义同一行内的元素,跟<div>的唯一区别是不产生转行
<layer>是ns的标记,ie不支持,相当于<div>
让弹出窗口总是在最上面
<body onblur="this.focus();">
电子邮件处理提交表单
<form name="form1" method="post" action="mailto:****@***.com" enctype="text/plain">
<input type=submit>
</form>
限制下拉选择的宽度
<select name="select" style="width:300"></select>
弹出的窗口居中
一:
<script>
myWin=window.open("about:blank","","width=200,height=160");
myWin.moveTo(screen.width/2-100,screen.height/2-80);
</script>
二:
<script>
t = 200;
l = 200;
window.open('about:blank','','width='+l+',height='+t+',top='+(screen.availHeight/2-t/2)+',left='+(screen.availWidth/2-l/2));
</script>
<script>
window.showModalDialog("about:<script>window.open('','w_name','status=no');window.close()<\/script>","","dialogwidth=0px;dialogheight=0px") //用模式窗口做个过度就可以了
window.open("你要弹出的地址","w_name","")
</script>
有关title换行的问题
<a href="/" title="51js 无忧脚本 逍遥云">无忧脚本</a>
背景图片居中
<body style="background-image: url(http://www.yesky.com/image20010518/122306.gif); background-attachment: fixed; background-repeat: no-repeat; background-position: center"></body>
<div style="position:absolute;left:expression(document.body.clientWidth/2-10);top:expression(document.body.clientHeight/2-10);">
<img src="http://bbs.51js.com/images/smilies/smile.gif">
</div>
引入样式表(css)的四种方式
一、使用STYLE属性: 将STYLE属性直接加在个别的元件标签里。
<元件(标签) STYLE="性质(属性)1: 设定值1; 性质(属性)2: 设定值2; ...}
例如:
<TD STYLE="COLOR:BLUE; font-size:9pt; font-family:"标楷体"; line-height:150%>
这种用法的优点 是可灵巧应用样式於各标签中,但是缺点则是没有整篇文件的『统一性』。
二、使用STYLE标签: 将样式规则写在<STYLE>...</STYLE>标签之中。
<STYLE TYPE="text/css">
<!--
样式规则表
-->
</STYLE>
例如:
<STYLE TYPE="text/css">
<!--
BODY {
color: BLUE;
background: #FFFFCC;
font-size: 9pt}
TD, P {
COLOR: GREEN;
font-size: 9pt}
-->
</STYLE>
通常是将整个的 <STYLE>...</STYLE>结构写在网页的<HEAD> </HEAD>部份之中。这种用法的优点就是在於整篇文件的统一性,只要是有声明的的元件即会套用该样式规则。缺点就是在个别元件的灵活度不足。
三、使用 LINK标签: 将样式规则写在.css的样式档案中,再以<LINK>标签引入。
假设我们把样式规则存成一个example.css的档案,我们只要在网页中加入
<LINK REL=STYLESHEET TYPE="text/css" HREF="example.css">
即可套用该样式档案中所制定好的样式了。 通常是将LINK标签写在网页的<head></head>部份之中。这种用法的优点就是在於可以把要套用相同样式规则的数篇文件都指定到同一个样式档案即可。缺点也是在个别文件或元件的灵活度不足。
四、使用@import引入: 跟LINK用法很像,但必 放在<STYLE>...</STYLE> 中。
<STYLE TYPE="text/css">
<!--
@import url(引入的样式表的位址、路径与档名);
-->
</STYLE>
例如:
<STYLE TYPE="text/css">
<!--
@import url(http://yourweb/ example.css);
-->
</STYLE>
链接时候下陷效果
<style>
A:link,A:visited ,A:active {TEXT-DECORATION: none}
A:hover {text-decoration : none; position : relative; top : 1px; left : 1px}
</style>
<A HREF="http://be10.ods.org/51js/forumdisplay.php?fid=9">来来,都到这里来……</A>
<A HREF="http://winsky0.yeah.net">你把一个人看简单了,这个人就是winsky……*&^(*(*)</A>
以上来自51js各个版主发布的经典脚本,具体查看www.51js.com;