一些js代碼

<!--

1. οncοntextmenu="window.event.returnValue=false" 將徹底屏蔽鼠標右鍵
<table border οncοntextmenu=return(false)><td>no</table> 可用於Table

2. <body onselectstart="return false"> 取消選取、防止複製

3. οnpaste="return false" 不準粘貼

4. οncοpy="return false;" oncut="return false;" 防止複製

5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址欄前換成自己的圖標

6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夾中顯示出你的圖標

7. <input style="ime-mode:disabled"> 關閉輸入法

8. 永遠都會帶着框架
<script language="JavaScript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm爲框架網頁
// --></script>

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

10. <noscript><iframe src=*.html></iframe></noscript> 網頁將不能被另存爲

11. <input type=button value=查看網頁源代碼
οnclick="window.location = 'view-source:'+ 'http://www.csdn.net/'">

12. 一段JavaScript的關機代碼

win98/me
<script language="JavaScript">
var wsh = new ActiveXObject("WScript.Shell");
wsh.Run("rundll32.exe user.exe,exitWindows");
</script>

win2000 or xp
<script language="JavaScript">
var wsh = new ActiveXObject("WScript.Shell");
wsh.sendKeys("^{ESC}");
wsh.sendKeys("{UP}~S~");
</script>

13. 取得控件的絕對位置

//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);
}
</script>

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

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

15. 調用客戶端的程序
<script>
var wsh=new ActiveXObject("wscript.shell")
wsh.run("notepad.exe")
</script>

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=最小化 οnclick=hh1.Click()>
<input type=button value=最大化 οnclick=hh2.Click()>
<input type=button value=關閉 οnclick=hh3.Click()>
本例適用於IE

17. 屏蔽 Alt+F4
<script language=Javascript>
function document.onkeydown()
{
if ((window.event.altKey)&&(window.event.keyCode==115)){
window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");
return false;}
}
</script>

18. 自己動手爲string添加Trim
<script language=Javascript>
String.prototype.Trim=function(){return this.replace(/(^/s*)|(/s*$)/g,"");}
String.prototype.Ltrim = function(){return this.replace(/(^/s*)/g, "");}
String.prototype.Rtrim = function(){return this.replace(/(/s*$)/g, "");}
var str = " abc de ";
alert(str.Trim());
</script>

19. 檢查一段字符串是否全由數字組成
<script language="Javascript"><!--
function checkNum(str){return str.match(//D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// --></script>

20. 獲得一個窗口的大小
document.body.clientWidth,document.body.clientHeight

21. 怎麼判斷是否是字符
if (/[^/x00-/xff]/g.test(s)) alert("含有漢字");
else alert("全是字符");

22.TEXTAREA自適應文字行數的多少
<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight">
</textarea>

23. 日期減去天數等於第二個日期
<script language=Javascript>
function cc(dd,dadd)
{
//可以加上錯誤處理
var a = new Date(dd)
a = a.valueOf()
a = a - dadd * 24 * 60 * 60 * 1000
a = new Date(a)
alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")
}
cc("12/23/2002",2)
</script>

24. 選擇了哪一個Radio
<HTML><script language="vbscript">
function checkme()
for each ob in radio1
if ob.checked then window.alert ob.value
next
end function
</script><BODY>
<INPUT name="radio1" type="radio" value="style" checked>Style
<INPUT name="radio1" type="radio" value="barcode">Barcode
<INPUT type="button" value="check" οnclick="checkme()">
</BODY></HTML>

25.獲得本頁url的request.servervariables("")集合
Response.Write "<TABLE border=1><!-- Table Header --><TR><TD><B>Variables</B></TD><TD><B>Value</B></TD></TR>"
for each ob in Request.ServerVariables
Response.Write "<TR><TD>"&ob&"</TD><TD>"&Request.ServerVariables(ob)&"</TD></TR>"
next
Response.Write "</TABLE>"

26.
本機ip<%=request.servervariables("remote_addr")%>
服務器名<%=Request.ServerVariables("SERVER_NAME")%>
服務器IP<%=Request.ServerVariables("LOCAL_ADDR")%>
服務器端口<%=Request.ServerVariables("SERVER_PORT")%>
服務器時間<%=now%>
IIS版本<%=Request.ServerVariables"SERVER_SOFTWARE")%>
腳本超時時間<%=Server.ScriptTimeout%>
本文件路徑<%=server.mappath(Request.ServerVariables("SCRIPT_NAME"))%>
服務器CPU數量<%=Request.ServerVariables("NUMBER_OF_PROCESSORS")%>
服務器解譯引擎<%=ScriptEngine & "/"& ScriptEngineMajorVersion &"."&ScriptEngineMinorVersion&"."& ScriptEngineBuildVersion %>
服務器操作系統<%=Request.ServerVariables("OS")%>

27.ENTER鍵可以讓光標移到下一個輸入框
<input οnkeydοwn="if(event.keyCode==13)event.keyCode=9">

28. 檢測某個網站的鏈接速度:
把如下代碼加入<body>區域中:
<script language=Javascript>
tim=1
setInterval("tim++",100)
b=1

var autourl=new Array()
autourl[1]="http://www.njcatv.net"
autourl[2]="javacool.3322.net"
autourl[3]="http://www.sina.com.cn"
autourl[4]="http://www.nuaa.edu.cn"
autourl[5]="http://www.cctv.com"

function butt(){
document.write("<form name=autof>")
for(var i=1;i<autourl.length;i++)
document.write("<input type=text name=txt"+i+" size=10 value=測試中……> =》<input type=text name=url"+i+" size=40> =》<input type=button value=GO οnclick=window.open(this.form.url"+i+".value)><br/>")
document.write("<input type=submit value=刷新></form>")
}
butt()
function auto(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++
}
function run(){for(var i=1;i<autourl.length;i++)document.write("<img src=http://"+autourl[i]+"/"+Math.random +".length;i++)document.write("<img src=http://"+autourl[i]+"/"+Math.random()+" width=1 height=1 οnerrοr=auto('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

30.實現另存爲:
<input type=button value=保存 οnclick=document.execCommand('SaveAs')>

31.窗口最大化(全屏顯示不帶工具欄等):
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</head>
<input type=button value=最大化 οnclick="javascript:new ActiveXObject('wscript.shell').sendKeys('{F11}')">
</BODY>
</HTML>


32.

<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0>
</OBJECT>
<input οnclick=document.all.WebBrowser.ExecWB(1,1) type=button value=打開 name=Button1>
<input οnclick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存爲 name=Button2>
<input οnclick=document.all.WebBrowser.ExecWB(10,1) type=button value=屬性 name=Button3>
<input οnclick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印 name=Button>
<input οnclick=document.all.WebBrowser.ExecWB(8,1) type=button value=頁面設置 name=Button4>
<br/>
<input οnclick=window.location.reload() type=button value=刷新 name=refresh>
<input οnclick="window.external.ImportExportFavorites(true,'');" type=button value=導入收藏夾 name=Button5>
<input οnclick="window.external.ImportExportFavorites(false,'');" type=button value=導出收藏夾 name=Button32>
<input οnclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏夾 name=Button22>
<br/>
<input οnclick="window.external.ShowBrowserUI('OrganizeFavorites', null)" type=button value=整理收藏夾 name=Submit2>
<input οnclick='window.location="view-source:" + window.location.href' type=button value=查看源文件 name=Button7>
<input οnclick="window.external.ShowBrowserUI('LanguageDialog', null)" type=button value=語言設置 name=Button6>
<input οnclick=history.go(1) type=submit value=前進 name=Submit>
<input οnclick=history.go(-1) type=submit value=後退 name=Submit2>
要完成此效果把如下代碼加入到<body>區域中

<input type="button" name="Button" value="點擊保存頁面" onClick="document.all.WebBrowser.ExecWB(4,1)">
<object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</object>
………………………………………………………………………………………………………………………………
鼠標自定義
<script language=javascript>var Loaded=false;var Flag=false;</script>
<script src='http://files.cometsystems.com/&#106avascript/lc2000.js'
language=javascript></script>
<script language=javascript>if(Loaded&&Flag)TheCometCursor('cd_electric',0,626);</script>


要完成此效果把如下代碼加入到<head>區域中

<SCRIPT LANGUAGE="javascript">
<!-- Begin
var x, y, xold, yold, xdiff, ydiff;
var dir = Array();
dir[0] = "n-resize";
dir[1]="ne-resize";
dir[2]="e-resize";
dir[3]="se-resize";
dir[4] = "s-resize";
dir[5]="sw-resize";
dir[6]="w-resize";
dir[7]="nw-resize";
document.onmousemove = FindXY;
function display(direction) {
document.body.style.cursor = dir[direction];
}
function FindXY(loc) {
x = (document.layers) ? loc.pageX : event.clientX;
y = (document.layers) ? loc.pageY : event.clientY;
xdiff = x - xold;
ydiff = y - yold
if ((xdiff < 2) && (ydiff < -2)) display(0);
if ((xdiff < 2) && (ydiff > 2)) display(4);
if ((xdiff > 2) && (ydiff < 2)) display(2);
if ((xdiff < -2) && (ydiff < 2)) display(6);
if ((xdiff > 2) && (ydiff > 2)) display(3);
if ((xdiff > 2) && (ydiff < -2)) display(1);
if ((xdiff < -2) && (ydiff > 2)) display(5);
if ((xdiff < -2) && (ydiff < -2)) display(7);
xold = x;
yold = y;
}
// End -->
</script>

<input type=button value=剪切 οnclick=document.execCommand('Cut')>
<input type=button value=拷貝 οnclick=document.execCommand('Copy')>
<input type=button value=粘貼 οnclick=document.execCommand('Paste')>
<input type=button value=撤消 οnclick=document.execCommand('Undo')>
<input type=button value=刪除 οnclick=document.execCommand('Delete')>
<input type=button value=黑體 οnclick=document.execCommand('Bold')>
<input type=button value=斜體 οnclick=document.execCommand('Italic')>
<input type=button value=下劃線 οnclick=document.execCommand('Underline')>
<input type=button value=停止 οnclick=document.execCommand('stop')>
<input type=button value=保存 οnclick=document.execCommand('SaveAs')>
<input type=button value=另存爲 οnclick=document.execCommand('Saveas',false,'c://test.htm')>
<input type=button value=字體 οnclick=document.execCommand('FontName',false,fn)>
<input type=button value=字體大小 οnclick=document.execCommand('FontSize',false,fs)>
<input type=button value=刷新 οnclick=document.execCommand('refresh',false,0)>

<input type=button value=刷新 οnclick=window.location.reload()>
<input type=button value=前進 οnclick=history.go(1)>
<input type=button value=後退 οnclick=history.go(-1)>
<input type=button value=前進 οnclick=history.forward()>
<input type=button value=後退 οnclick=history.back()>

<input type=button value=導入收藏夾 οnclick=window.external.ImportExportFavorites(true,"http://localhost" ;>
<input type=button value=導出收藏夾 οnclick=window.external.ImportExportFavorites(false,"http://localhost" ;>
<input type=button value=整理收藏夾 οnclick="window.external.ShowBrowserUI('OrganizeFavorites', null)">
<input type=button value=查看源文件 οnclick="window.location = 'view-source:'+ window.location.href">
<input type=button value=語言設置 οnclick="window.external.ShowBrowserUI('LanguageDialog', null)">
<input type=button value=加入收藏夾 οnclick="window.external.AddFavorite(','')">
<input type=button value=加入到頻道 οnclick="window.external.addChannel('' ">
<input type=button value=設成主頁 οnclick="this.style.behavior='url(#default#homepage)';this.setHomePage('' ">

<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT>
<input type=button value=打開 οnclick=document.all.WebBrowser.ExecWB(1,1)>
<input type=button value=另存爲 οnclick=document.all.WebBrowser.ExecWB(4,1)>
<input type=button value=全選 οnclick=document.all.WebBrowser.ExecWB(17,1)>
<input type=button value=屬性 οnclick=document.all.WebBrowser.ExecWB(10,1)>
<input type=button value=關閉窗口 οnclick=document.all.WebBrowser.ExecWB(45,1)>
<input type=button value=打印 οnclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 οnclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=頁面設置 οnclick=document.all.WebBrowser.ExecWB(8,1)>
<input type=button value=打印預覽 οnclick=document.all.WebBrowser.ExecWB(7,1)>

 

<body><SCRIPT LANGUAGE="JavaScript">
var s = "網頁正文部分寬:"+ document.body.clientWidth;
s += "/r/n網頁正文部分高:"+ document.body.clientHeight;
s += "/r/n網頁正文部分上:"+ window.screenTop;
s += "/r/n網頁正文部分左:"+ window.screenLeft;
s += "/r/n屏幕分辨率的高:"+ window.screen.height;
s += "/r/n屏幕分辨率的寬:"+ window.screen.width;
s += "/r/n屏幕可用工作區高度:"+ window.screen.availHeight;
s += "/r/n屏幕可用工作區寬度:"+ window.screen.availWidth;
alert(s);
</SCRIPT>


33.取下拉菜單的值
document.all("listbox1").options[document.all("listbox1").selectedIndex].value
document.all("listbox1").options[document.all("listbox1").selectedIndex].text


-->

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章