日期:2014-05-16  浏览次数:20318 次

javascript的40个网页常用小技巧
1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border><td>no</td></table> 可用于Table

2.  取消选取、防止复制

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

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

5. &lt;link rel="Shortcut Icon" href="favicon.ico"&gt; IE地址栏前换成自己的图标

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

7. <input style=""> 关闭输入法

8. 永远都会带着框架
&lt;script language="JavaScript"&gt;&lt;!--
if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页
// --&gt;&lt;/script&gt;

9. 防止被人frame
&lt;script language="JAVASCRIPT"&gt;&lt;!--
if (top.location != self.location)top.location=self.location;
// --&gt;&lt;/script&gt;

10. 网页将不能被另存为
&lt;noscript&gt;&lt;iframe src="/blog/*.html&amp;gt;"&gt;&lt;/iframe&gt;&lt;/noscript&gt;

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

12.删除时确认
<a>删除</a>

13. 取得控件的绝对位置
//Javascript
&lt;script language="Javascript"&gt;
function getIE(e){
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent)
alert("top="+t+"/nleft="+l);
}
&lt;/script&gt;

//VBScript
&lt;script language="VBScript"&gt;&lt;!--
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&lt;&gt;"BODY"
set a = a.offsetParent
t=t+a.offsetTop
l=l+a.offsetLeft
wend
msgbox "top="&amp;t&amp;chr(13)&amp;"left="&amp;l,64,"得到控件的位置"
end function
--&gt;&lt;/script&gt;

14. 光标是停在文本框文字的最后
&lt;script language="javascript"&gt;
function cc()
{
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart("character",e.value.length);
r.collapse(true);
r.select();
}
&lt;/script&gt;<input type="text" name="text1" value="123">

15. 判断上一页的来源
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="最小化"><input type="button" value="最大化"><input type="button" value="关闭">
本例适用于IE

17.屏蔽功能键Shift,Alt,Ctrl
&lt;script&gt;
function look(){
if(event.shiftKey)
alert("禁止按Shift键!"); //可以换成ALT CTRL
}
document.onkeydown=look;
&lt;/script&gt;

18. 网页不会被缓存
&lt;meta http-equiv="pragma" content="no-cache"&gt;
&lt;meta http-equiv="Cache-Control" content="no-cache, must-revalidate"&gt;
&lt;meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT"&gt;
或者&lt;meta http-equiv="expires" content="0"&gt;

19.怎样让表单没有凹凸感?
<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;">

20.<div><span>&amp;&lt;layer&gt;的区别?
&lt;div&gt;(division)用来定义大段的页面元素,会产生转行
&lt;span&gt;用来定义同一行内的元素,跟&lt;div&gt;的唯一区别是不产生转行
&lt;layer&gt;是ns的标记,ie不支持,相当于&lt;div&gt;

21.让弹出窗口总是在最上面:


22.不要滚