经典js代码收藏
判断上一页的来源
javascript:document.referrer
在打开的子窗口刷新父窗口的代码里如何写?
window.opener.location.reload()
电子邮件处理提交表单
<form name="form1" method="post" action="mailto:****@***.com" enctype="text/plain">
<input type=submit>
</form>
<input type=submit>
</form>
怎样去掉图片链接点击后,图片周围的虚线?
<a href="#" onFocus="this.blur()"><img src="logo.jpg" border=0></a>
如何设定打开页面的大小
<body onload="top.resizeTo(300,200);">
获得一个窗口的大小
document.body.clientWidth; document.body.clientHeight
ENTER键可以让光标移到下一个输入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9">
网页是否被检索
<meta name="ROBOTS" content="属性值">
其中属性值有以下一些:
属性值为"all": 文件将被检索,且页上链接可被查询;
属性值为"none": 文件不被检索,而且不查询页上的链接;
属性值为"index": 文件将被检索; 属性值为"follow": 查询页上的链接;
属性值为"noindex": 文件不检索,但可被查询链接;
属性值为"nofollow": 文件不被检索,但可查询页上的链接。
其中属性值有以下一些:
属性值为"all": 文件将被检索,且页上链接可被查询;
属性值为"none": 文件不被检索,而且不查询页上的链接;
属性值为"index": 文件将被检索; 属性值为"follow": 查询页上的链接;
属性值为"noindex": 文件不检索,但可被查询链接;
属性值为"nofollow": 文件不被检索,但可查询页上的链接。
层的隐藏与显示
只要设置style的display属性即可
比如<div style="display:none" id="MyDiv">隐藏的层</div>
如果要显示它可以通过脚本来控制
window.document.getElementById("MyDiv").style.display = "";
禁止右键
<body oncontextmenu="return false">
屏蔽页面中程序运行出错信息
window.onerror = function()
{
return true;
}
得到当前显示器的分辨率
window.srceen.width 得到屏幕的宽度
window.srceen.height 得到屏幕的高度
如果当前分辨率为800*600,window.srceen.width是800,window.srceen.height是600
定时运行特定代码
setTimeout(Code,Timeout);
setInterval(Code,Timeout);
Code是一段字符串,里边是js代码,Timeout是时间间隔,单位是微秒
setTimeout是从现在算起多少微秒后运行该代码(只运行一次)
setInterval是每隔多少微秒运行一次代码
得到本页网址
var Url = window.location.href;
保存当前页面的内容
document.execCommand("SaveAs","","C:\\index.htm");
浙公网安备 33010602011771号