`

做网页常常用到的js代码大全

阅读更多
留着肯定会有用到的。
1、后退 前进
<input onclick=”history.go(-1)” type=”button” value=”后退” />
<input onclick=”history.go( 1 );return true;” type=”button” value=”前进” />

2、返回

<form><input onclick=”history.back(-1)” type=”button” value=”返回上一步” /></form>3、查看源码
<input onclick=”window.location=” name=”view” type=”button” value=”查看源码” />

4、禁止查看源码

5、刷新按钮一
<input onclick=”ReloadButton()” type=”button” value=”刷新按钮一” />
<script type=”text/javascript”>// <![CDATA[
function ReloadButton(){location.href="i001.htm";}
// ]]></script>

刷新按钮二
<input onclick=”history.go(0)” type=”button” value=”刷新按钮二” />

6、回首页按钮
<input onclick=”HomeButton()” type=”button” value=”首页” />
<script type=”text/javascript”>// <![CDATA[
function HomeButton(){location.href=http://www.winliuxq.com;}
// ]]></script>

7、弹出警告框
<input onclick=”AlertButton()” type=”button” value=”弹出警告框” />
<script type=”text/javascript”>// <![CDATA[
function AlertButton(){window.alert("要多多光临呀!");}
// ]]></script>

8、状态栏信息
<input onclick=”StatusButton()” type=”button” value=”状态栏信息” />
<script type=”text/javascript”>// <![CDATA[
function StatusButton(){window.status="要多多光临呀!";}
// ]]></script>

这一页发不完,点查看全文看更多的吧!9、背景色变换

<form><input onclick=”BgButton()” type=”button” value=”背景色变换” /></form><script type=”text/javascript”>// <![CDATA[
function BgButton(){
if (document.bgColor=='#00ffff')
{document.bgColor='#ffffff';}
else{document.bgColor='#00ffff';}
}
// ]]></script>

10、打开新窗口
<input onclick=”NewWindow()” type=”button” value=”打开新窗口” />
<script type=”text/javascript”>// <![CDATA[
function NewWindow(){window.open("c01.htm","","height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no");}
// ]]></script>

11、窗口最小化
<object id=”min” classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ width=”100″ height=”100″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0″><param name=”Command” value=”Minimize” /><embed id=”min” type=”application/x-shockwave-flash” width=”100″ height=”100″ command=”Minimize”></embed></object><button onclick=”min.Click()”>窗口最小化</button>

12、全屏代码
<input onclick=”window.open(document.location, ‘butong_net’, ‘fullscreen’)” name=”FullScreen” type=”BUTTON” value=”全屏显示” />

13、关闭窗口
<object id=”closes” classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ width=”100″ height=”100″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0″><param name=”Command” value=”Close” /><embed id=”closes” type=”application/x-shockwave-flash” width=”100″ height=”100″ command=”Close”></embed></object><input onclick=”closes.Click();” type=”button” value=”关闭窗口” />

关闭窗口
<input onclick=”javascript:self.close()” type=”button” value=”关闭窗口” />

14、最大化
<object id=”big” classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ width=”100″ height=”100″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0″><param name=”Command” value=”Maximize” /><embed id=”big” type=”application/x-shockwave-flash” width=”100″ height=”100″ command=”Maximize”></embed></object><input onclick=”big.Click()” type=”button” value=”最大化” />

15、关闭输入法
<input style=”ime-mode: disabled;” value=”关闭输入法” />

16、链接按钮1
<input onclick=”window.open(‘http://www.winliuxq.com/’, ‘Sample’, ‘toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes,width=790,height=520,left=0,top=0′)” name=”input” type=”button” value=”链接按钮1″ />

链接按钮2
<input onclick=”showModalDialog(‘http://www.winliuxq.com/’)” name=”Button” type=”BUTTON” value=”链接按钮2″ />

链接按钮3
<input onclick=”location.href=’http://www.winliuxq.com/’” type=”submit” value=”链接按钮3″ />

17、警告框显示源代码
<button style=”width: 110px;” onclick=”alert(document.documentElement.outerHTML)”>警告框显示源代码</button>

18、点击后按钮清空
<input onclick=”this.style.visibility=’hidden’;window.print();” type=”button” value=”打印” />

19、打印
<input onclick=”window.print();” type=”button” value=”打印” />

20、打印预览
<object id=”wb” classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ width=”0″ height=”0″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0″><param name=”name” value=”wb” /><embed id=”wb” type=”application/x-shockwave-flash” width=”0″ height=”0″ name=”wb”></embed></object>
<input onclick=”wb.execwb(7,1)” type=”button” value=”打印预览” />

21、另存为
<input onclick=”document.execCommand(’saveas’,’true’,’常用代码.htm’)” type=”button” value=”另存为” />

22、点击自动复制
<script type=”text/javascript”>// <![CDATA[
function oCopy(obj){obj.select();js=obj.createTextRange();js.execCommand("Copy")}
// ]]></script>
<input onclick=”oCopy(this)” size=”11″ type=”text” value=”点击自动复制” />

23、自动选中
<input onmouseover=”this.focus()” size=”11″ value=”自动选中” />

24、打开源代码
<button onclick=”document.location = ‘view-source:’ + document.location”>打开源代码</button>

25、新窗口延迟打开
<input onclick=”javascript:setTimeout(&quot;window.open(‘http://www.winliuxq.com/’)&quot;,10000)” type=”button” value=”新窗口延迟打开” />

26、实现选中文本框里的前一半的内容
<input onmouseover=”this.select();tR=document.selection.createRange();tR.moveEnd(‘character’,-8);tR.select();” size=”30″ type=”text” value=”选中文本框里的前一半的内容” />
<input onmouseover=”this.selectionStart=this.value.length-4;this.selectionEnd=this.value.length” size=”30″ type=”text” value=”选中部分内容,非IE可以用这个” />

27、点击清空文字
<input onclick=”if(this.value==’点击清空文字’)this.value=”” onmouseover=”this.focus()” name=”artist” size=”14″ type=”text” value=”点击清空文字” />

点击清空文字
<input onclick=”if (this.value==’点击清空文字’) this.value=”” onmouseover=”this.focus()” name=”name” size=”11″ value=”点击清空文字” />

28、等于标题(title):
<input id=”aa” size=”20″ type=”text” />
<script type=”text/javascript”>// <![CDATA[
document.getElementById("aa").value=document.title;
// ]]></script>

29、检测IE是否脱机
<input onclick=”alert(window.navigator.onLine)” type=”button” value=”测试” />

30、11种刷新按钮的方法
<input onclick=”history.go(0)” type=”button” value=”刷新” />
<input onclick=”location.reload()” type=”button” value=”刷新” />
<input onclick=”location=location” type=”button” value=”刷新” />
<input onclick=”location.assign(location)” type=”button” value=”刷新” />
<input onclick=”document.execCommand(‘Refresh’)” type=”button” value=”刷新” />
<input onclick=”window.navigate(location)” type=”button” value=”刷新” />
<input onclick=”location.replace(location)” type=”button” value=”刷新” />
<input onclick=”window.open(‘自身的文件’,’_self’)” type=”button” value=”刷新” />
<input onclick=”document.all.WebBrowser.ExecWB(22,1)” type=”button” value=”刷新” />
<object id=”WebBrowser” classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ width=”0″ height=”0″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0″><embed id=”WebBrowser” type=”application/x-shockwave-flash” width=”0″ height=”0″></embed></object>

<form action=”自身的文件”><input type=”submit” value=”刷新” /></form><a id=”a1″ href=”自身的文件”></a><input onclick=”a1.click()” type=”button” value=”刷新” />

31、
<a onclick=”document.execCommand(&quot;open&quot;)” href=”#”>打开</a>

32、
<a onclick=”window.open(‘i001.htm’,”,’height=300,width=300,resizable=no,location=net’);”>打开指定大小网页</a>

33、
<a onclick=”location.replace(&quot;view-source:&quot;+location)” href=”#”>使用 记事本 编辑</a>

34、
<a onclick=”document.execCommand(&quot;saveAs&quot;)” href=”#”>另存为</a>

35、
<a onclick=”document.execCommand(&quot;print&quot;)” href=”#”>打印</a>
<a href=”javascript:window.print();”>打印</a>

36、
<a href=”mailto:429752806@163.com”>发送E-mail</a>

37、
<a onclick=”document.execCommand(&quot;selectAll&quot;)” href=”#”>全选</a>

38、
<a onclick=”location.reload()” href=”#”>刷新1</a>

39、
<a onclick=”history.go(0)” href=”#”>刷新2</a>

40、
<a onclick=”location.replace(&quot;view-source:&quot;+location)” href=”#”>查看源文件</a>

41、
<a onclick=”window.open(document.location,&quot;url&quot;,&quot;fullscreen&quot;)” href=”#”>全屏显示</a>

<a onclick=”window.open(document.location,&quot;url&quot;,&quot;fullscreen&quot;)” href=”#”>42、
</a><a onclick=”window.external.showBrowserUI(&quot;PrivacySettings&quot;,null)” href=”#”> internet选项</a>

43、
<a href=”#”>单击右键将在新窗口中打开</a>

44、
<a onclick=”history.go(1)” href=”#”>前进1</a>

<a onclick=”history.forward()” href=”#”>前进2</a>

<a onclick=”history.go(-1)” href=”#”>后退1</a>

<a onclick=”history.back()” href=”#”>后退2</a>

45、
<a onclick=”window.external.showBrowserUI(&quot;OrganizeFavorites&quot;,null)” href=”#”>整理收藏夹</a>

<span style=”cursor: hand;” title=”网页特效站点” onclick=”window.external.addFavorite(‘http://www.winliuxq.com/’,’网页特效站点 ‘)”>加入收藏</span>

<a title=”百度” onclick=”try{if(document.all) {window.external.addFavorite(‘http://www.baidu.com/’,’百度’);} else {window.sidebar.addPanel(‘百度’,’http://www.baidu.com/’,”);}}catch(e){};return false;” href=”http://www.baidu.com/” target=”_self”>添加到收藏夹</a>

<a title=”百度” onclick=”try{if(document.all) {window.external.addFavorite(‘http://www.baidu.com/’,’百度’);} else {window.sidebar.addPanel(‘百度’,’http://www.baidu.com/’,”);}}catch(e){};return false;” href=”http://www.baidu.com/” target=”_self”>点击加入收藏夹</a>

<a onmouseover=”try{if(document.all) {window.external.addFavorite(‘http://www.baidu.com/’,’百度’);} else {window.sidebar.addPanel(‘百度’,’http://www.baidu.com/’,”);}}catch(e){};return false;” href=”http://www.baidu.com/” target=”_self”>鼠标感应收藏本站</a>

<a onmouseover=”this.style.behavior=’url(#default#homepage)’;this.setHomePage(‘http://www.yiloo.com/js/’);” href=”#” target=”_self”>鼠标感应设为首页</a>

46、
<a href=”javascript:window.close()”>关闭窗口</a>

<a onclick=”window.close();return” href=”#”>关闭窗口</a>

<a onclick=”setTimeout(window.close(),3000)” href=”#”>3秒关闭本窗口</a>

<script type=”text/javascript”>// <![CDATA[
function shutwin(){
window.close();
return;}
// ]]></script>
<a href=”javascript:shutwin();”>关闭本窗口</a>

47、<span style=”cursor: hand;” onclick=”var strHref=window.location.href;this.style.behavior=’url(#default#homepage)’;this.setHomePage(‘http://www.winliuxq.com/’);”>设为首页</span>

48、等于标题栏:<script type=”text/javascript”>// <![CDATA[
document.write(document.title);
// ]]></script>

49、
<a onclick=”window.external.AddFavorite(location.href, document.title);” href=”javascript:void(0);”>收藏本页</a>

<a href=”javascript:window.external.AddFavorite(document.location.href, document.title)”>收藏本页</a>

<a href=”javascript:window.external.addChannel(“>加入频道</a>

<a href=”javascript:window.external.addChannel(“>50、
</a><a onclick=”return false;” ondblclick=”window.open(‘i003.htm’);” href=”i003.htm”>双击打开链接</a>

51、
<!– #close a:hover {background:url(javascript:window.opener=0;window.close());} –>
<div id=”close”><a>关闭窗口</a></div>
52、
<a onmouseover=”alert(‘对不起,禁止选中!’)” href=”javascript:void(0)”>链接禁止</a>

53、滚动条在左侧,将改为

54、网页半透明

55、随机选择背景色

<script type=”text/javascript”>// <![CDATA[
document.body.style.background=(["red","blue","pink","navy","gray","yellow","green","purple"])[parseInt(Math.random()*8)];
// ]]></script>

56、框架页中不显示滚动条:
<script type=”text/javascript”>// <![CDATA[

self.moveTo(0,0)
self.resizeTo(screen.availWidth,screen.availHeight)
// ]]></script>

57、防止网页被框架
<script type=”text/javascript”>// <![CDATA[

if (top.location !== self.location) {
top.location=self.location;
}
// ]]></script>

58、永远都会带着框架
<script type=”text/javascript”>// <![CDATA[
if (window == top)top.location.href = "frame.htm"; //frame.htm为框架网页
// ]]></script>

59、窗口自动最大化
<script type=”text/javascript”>// <![CDATA[
self.moveTo(0,0)    self.resizeTo(screen.availWidth,screen.availHeight)
// ]]></script>

60、打开窗口自动最大化
<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ width=”100″ height=”100″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0″><param name=”Command” value=”Maximize” /><embed type=”application/x-shockwave-flash” width=”100″ height=”100″ command=”Maximize”></embed></object>

61、爽眼闪屏代码
<script type=”text/javascript”>// <![CDATA[
var color = new Array;color[1] = “black”;color[2] = “white”;for(x = 0; x <3; x++){document.bgColor = color[x];if(x == 2){x = 0;}}
// ]]></script>

62、不能被另存为
<noscript><iframe src=*.html></iframe></noscript>

63、汉字字库调用
<script type=”text/javascript”>// <![CDATA[
for(i=19968;i<40870;i++)document.write(String.fromCharCode(i));
// ]]></script>

64、显示现在时间的脚本
<script type=”text/javascript”>// <![CDATA[
document.write now
// ]]></script>

65、显示最后修改时间的脚本
<script type=”text/javascript”>// <![CDATA[
document.write(document.lastModified)
// ]]></script>

66、按下F12键,直接返回首页
<script type=”text/javascript”>// <![CDATA[
function look(){
if(event.keyCode==123){document.location.href=http://www.winliuxq.com/}
}
if(document.onkeydown==null)
{document.onkeydown=look}
// ]]></script>

67、端口检测

<img src=”http://www.winliuxq/zza.jpg” alt=”” />

68、无法最小化的窗口

69、链接点外部css文件
<!– @import url(“ie.css”); –>

70、内嵌式框架-网页中调用另外网页:
<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ width=”600″ height=”1000″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0″><param name=”src” value=”http://www.winliuxq.com/” /><embed type=”application/x-shockwave-flash” width=”600″ height=”1000″ src=”http://www.winliuxq.com/”></embed></object>

71、刷新改变窗口大小
<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ width=”100″ height=”100″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0″><param name=”Command” value=”Maximize” /><embed type=”application/x-shockwave-flash” width=”100″ height=”100″ command=”Maximize”></embed></object>

72、JavaScript实现网页竖虚线
<script type=”text/javascript”>// <![CDATA[
hei=120;d1=2;d2=2;cou=Math.floor(hei/(d1+d2));
document.write('
<table cellspacing=0 cellpadding=0 width=1 height='+hei+'>');
for(i=0;i<cou;i++){document.write('
<tr>
<td height='+d2+'>
<tr>
<td height='+d1+' bgcolor=333333>')}
// ]]></script>

73、js翻页
<script type=”text/javascript”>// <![CDATA[
document.write("<a href="+location.href.replace(/\.html/g,"_2.html")+">2</a>");
// ]]></script>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics