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

部分常用JavaScript代码
自动刷新
<meta HTTP-EQUIV="refresh" CONTENT="8;URL=http://c98.yeah.net">
禁止右键
document.oncontextmenu = function() { return false;}
禁止保存
<noscript><iframe src="*.htm"></iframe></noscript>
禁止选取<body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false"onmouseup="document.selection.empty()>
禁止粘贴
<input type=text onpaste="return false">
地址栏图标
<link rel="Shortcut Icon" href="favicon.ico">
favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下
收藏栏图标
<link rel="Bookmark" href="favicon.ico">
查看源码
<input type=button value=查看网页源代码 onclick="window.location = 'view-source:'+ 'http://www.csdn.net/'">
关闭输入法
<input style="ime-mode:disabled">
自动全选
<input type=text name=text1 value="123" onfocus="this.select()">
ENTER键可以让光标移到下一个输入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9">
文本框的默认值

<body onload="window.resizeTo(window.screen.width - 4,window.screen.height-50);window.moveTo(-4,-4)">

66.设置为主页
function makeHome(){
netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
navigator.preference("browser.startup.homepage", location.href);
}//

67.设置为收藏
function addFav(){
if(ie)
    window.external.AddFavorite(location.href,'WWW.OGRISH.COM : GROTESQUE MOVIES AND PICTURES');
if(ns)
    alert("Thanks for the bookmark!\n\nNetscape users click OK then press CTRL-D");
}//

68.判断cookie是否可用
navigator.cookieEnabled;//

71.禁止选择页面上的文字来拷贝
<script>
function noEffect() {
with (event) {
    returnValue = false;
    cancelBubble = true;
}
return;
}
</script>
<body onselectstart="noEffect()" oncontextmenu="noEffect()">//
74.禁止在输入框打开输入法
<input style="ime-mode: disabled">//
109.改变状态栏
self.status ="";//

110.改变窗口大小
window.resizeTo(200,300);//

111.改变鼠标样式
style
BODY{CURSOR: url('mouse.ani');
SCROLLBAR-BASE-COLOR: #506AA8;
SCROLLBAR-ARROW-COLOR: #14213F;
}//

112.背景透明
<input type="button" value="Button" style="background-color: transparent; border: 0;">//

113.鼠标为等待形状
<input type=button onclick="this.style.cursor='wait'">//
<button onclick="text1.scrollTop=text1.scrollHeight">Scroll</button><br>
<textarea id="text1" cols=50 rows=10>