JavaScript对IE操作的经典代码(推荐)

时间:2021-05-26

这段时间一直在用ajax技术做东东,所以也就有更多机会对JavaScript知识进行学习。之前在网上搜集了一些关于JavaScript对IE操作的代码(具体在哪里cope的记不清了,所以出处就不加了),感觉在开发过程中很有用,当然只适用于IE,FF会有问题的。现在贴出来分享。
复制代码 代码如下:
1.将彻底屏蔽鼠标右键
oncontextmenu="window.event.returnvalue=false"
可用于Table<table oncontextmenu=return(false)><td>no</table>

2.取消选取、防止复制
<bodyonselectstart="returnfalse">

3.不准粘贴
onpaste="returnfalse"

4.防止复制
oncopy="returnfalse;"
oncut="returnfalse;"

5.IE地址栏前换成自己的图标
<linkrel="ShortcutIcon"href="favicon.ico">

6.可以在收藏夹中显示出你的图标
<linkrel="Bookmark"href="favicon.ico">

7.关闭输入法
<inputstyle="ime-mode:disabled">

8.永远都会带着框架
<scriptlanguage="javascript">
<!--
if(window==top)top.location.href="frames.htm";
//-->
</script>

9.防止被人frame
<SCRIPTLANGUAGE=javascript>
<!--
if(top.location!=self.location)top.location=self.location;
//-->
</SCRIPT>

10.网页将不能被另存为
<noscript><iframesrc=*.html></iframe></noscript>

11.查看网页源代码
<input type=button value=查看网页源代码 onclick="window.location='view-source:'+'https://"
functionbutt(){
document.write("<formname=autof>")
for(vari=1;i<autourl.length;i++)
document.write("<inputtype=textname=txt"+i+"size=10value=测试中……>=》<inputtype=textname=url"+i+"size=40>=》<inputtype=buttonvalue=GOonclick=window.open(this.form.url"+i+".value)><br/>")
document.write("<inputtype=submitvalue=刷新></form>")
}
butt()
functionauto(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++
}
functionrun(){for(vari=1;i<autourl.length;i++)document.write("<imgsrc=http://"+autourl[i]+"/"+Math.random()+"width=1height=1onerror=auto('< src="pic/url.gif" align=absMiddle border=0>http://";+autourl[i]+"')>")}
run()</script>

29.各种样式的光标
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

1.本地无缓存,每次自动刷新
response.expires=0
response.addHeader"pragma","no-cache"
response.addHeader"cache-control","private"

2.修改contentType并下载gif等格式
<%
functiondl(f,n)
onerrorresumenext
sets=CreateObject("Adodb.Stream")
S.Mode=3
S.Type=1
S.Open
s.LoadFromFile(server.mappath(f))
iferr.number>0then
response.writeerr.number&":"&err.description
else
response.contentType="application/x-gzip"
response.addheader"Content-Disposition:","attachment;filename="&n
response.binarywrite(s.Read(s.size))
endif
endfunction
calldl("012922501.gif","t1.gif")
%>

19.检查一段字符串是否全由数字组成
<scriptlanguage="javascript"><!--
functioncheckNum(str)...{return!/D/.test(str)}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
//--></script>

20.获得一个窗口的大小
document.body.clientWidth,document.body.clientHeight
document.body.offsetWidth,document.body.offsetHeight
有时还需要知道window.screenTop,window.screenLeft

21.怎么判断是否含有汉字
if(escape(str).indexOf("%u")!=-1)alert("含有汉字");
elsealert("全是字符");

22.TEXTAREA自适应文字行数的多少
IE5.5+可以用overflow-y:visible
<textarearows=1name=s1cols=27style="overflow-y:visible">
</textarea>

23.日期减去天数等于第二个日期
<scriptlanguage=javascript>
function cc(dd,dadd)
...{
//可以加上错误处理
vard=newDate(dd.replace("-","/"))
d.setDate(d.getDate()+dadd)
alert(d.getFullYear()+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日")
}
cc("2002-2-28",2)
</script>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章