73种网页常用Javascript代码

 

1、后退 前进  
<input type="button" value="后退" onClick="history.go(-1)">  
<input type="button" value="前进" onClick="history.go( 1 );return true;">

2、返回  
<form><input type="button" value="返回上一步" onClick="history.back(-1)"></form>

3、查看源码  
<input type="button" name="view" value="查看源码" onClick="window.location="view-source:" +window.location.href">

4、禁止查看源码  
<body oncontextmenu="return false"></body>

5、刷新按钮一  
<input type="button" value="刷新按钮一" onClick="ReloadButton()">  
<script>function ReloadButton(){location.href="i001.htm";}</script>

刷新按钮二  
<input type="button" value="刷新按钮二" onClick="history.go(0)">

6、回首页按钮  
<input type="button" value="首页" onClick="HomeButton()">  
<script>function HomeButton(){location.href=http://www.winliuxq.com;}</script>

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

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

9、背景色变换  
<form><input type="button" value="背景色变换" onClick="BgButton()"></form>  
<script>function BgButton(){  
if (document.bgColor=='#00ffff')  
   {document.bgColor='#ffffff';}  
else{document.bgColor='#00ffff';}  
}  
</script>

10、打开新窗口  
<input type="button" value="打开新窗口" onClick="NewWindow()">  
<script>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" type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"><PARAM name="Command" value="Minimize"></OBJECT><button onClick="min.Click()">窗口最小化</button>

12、全屏代码  
<input type="BUTTON" name="FullScreen" value="全屏显示" onClick="window.open(document.location, 'butong_net', 'fullscreen')">

13、关闭窗口  
<OBJECT id=closes type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"><param name="Command" value="Close"></object><input type="button" value="关闭窗口" onClick="closes.Click();">

关闭窗口  
<input type=button value=关闭窗口 onClick="javascript:self.close()">

14、最大化  
<object id=big classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">   
<param name="Command" value="Maximize"></object><input type=button value=最大化 onClick=big.Click()>

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

16、链接按钮1
<input type="button" value="链接按钮1" 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">

链接按钮2  
<input type="BUTTON" NAME="Button" value="链接按钮2" onClick="showModalDialog('http://www.winliuxq.com/')">

链接按钮3  
<input type="submit" value="链接按钮3" onClick="location.href='http://www.winliuxq.com/'">

17、警告框显示源代码  
<BUTTON onClick=alert(document.documentElement.outerHTML) style="width:110">警告框显示源代码</BUTTON>

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

19、打印  
<input type=button value='打印' onClick="window.print();">

20、打印预览  
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>  
<input type=button value=打印预览 onclick="wb.execwb(7,1)">

21、另存为  
<input onClick="document.execCommand('saveas','true','常用代码.htm')" type=button value=另存为>

22、点击自动复制  
<script>function oCopy(obj){obj.select();js=obj.createTextRange();js.execCommand("Copy")}</script>  
<input type="text" value="点击自动复制" onClick="oCopy(this)" size="11">

23、自动选中  
<input value="自动选中" onFocus="this.select()" onMouseOver="this.focus()" size="11">

24、打开源代码  
<BUTTON onClick="document.location = 'view-source:' + document.location" size="7">打开源代码</BUTTON>

25、新窗口延迟打开  
<input type=button value=新窗口延迟打开 onClick=javascript:setTimeout("window.open('http://www.winliuxq.com/')",10000)>

26、实现选中文本框里的前一半的内容  
<input type="text" value="选中文本框里的前一半的内容" size=30 onmouseover="this.select();tR=document.selection.createRange();tR.moveEnd('character',-8);tR.select();">  
<input type="text" value="选中部分内容,非IE可以用这个" size=30 onmouseover="this.selectionStart=this.value.length-4;this.selectionEnd=this.value.length">  
   
27、点击清空文字  
<input type="text" name="artist" size=14 value="点击清空文字" onmouseover=this.focus() onfocus=this.select() onclick="if(this.value=='点击清空文字')this.value=''">

点击清空文字  
<input name=name size=11 value=点击清空文字 onMouseOver=this.focus() onblur="if (this.value =='') this.value='点击清空文字'" onFocus=this.select() onClick="if (this.value=='点击清空文字') this.value=''">

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

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

30、11种刷新按钮的方法  
<input type=button value=刷新 onClick="history.go(0)">  
<input type=button value=刷新 onClick="location.reload()">  
<input type=button value=刷新 onClick="location=location">  
<input type=button value=刷新 onClick="location.assign(location)">  
<input type=button value=刷新 onClick="document.execCommand('Refresh')">  
<input type=button value=刷新 onClick="window.navigate(location)">  
<input type=button value=刷新 onClick="location.replace(location)">  
<input type=button value=刷新 onClick="window.open('自身的文件','_self')">  
<input type=button value=刷新 onClick=document.all.WebBrowser.ExecWB(22,1)>   
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>  
<form action="自身的文件"><input type=submit value=刷新></form>  
<a id=a1 href="自身的文件"></a><input type=button value=刷新 onClick="a1.click()">

31、  
<a href="#" onClick=document.execCommand("open")>打开</a>

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

33、
<a href="#" onClick=location.replace("view-source:"+location)>使用 记事本 编辑</a>

34、
<a href="#" onClick=document.execCommand("saveAs")>另存为</a>

35、
<a href="#" onClick=document.execCommand("print")>打印</a> 
<a href="javascript:window.print();">打印</a>

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

37、
<a href="#" onClick=document.execCommand("selectAll")>全选</a>

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

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

40、
<a href="#" onClick=location.replace("view-source:"+location)>查看源文件</a>

41、
<a href="#" onClick=window.open(document.location,"url","fullscreen")>全屏显示</a>

42、
<a href="#" onClick=window.external.showBrowserUI("PrivacySettings",null)>internet选项</a>

43、
<a href="#" oncontextmenu="window.open(this.href);return false;">单击右键将在新窗口中打开</a>

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

<a href="#" onClick=history.forward()>前进2</a>

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

<a href="#" onClick=history.back()>后退2</a>

45、
<a href="#" onClick=window.external.showBrowserUI("OrganizeFavorites",null)>整理收藏夹</a>

<SPAN onClick="window.external.addFavorite('http://www.winliuxq.com/','网页特效站点 ')" style="CURSOR: hand" title=网页特效站点>加入收藏</SPAN>

<a href="#" onClick="window.external.addFavorite('http://www.winliuxq.com/','网页特效站点')">添加到收藏夹</A>

<a href="javascript:window.external.AddFavorite('http://www.winliuxq.com/', '网页特效站点')">点击加入收藏夹</a>

<a href="#" onmouseover="window.external.addFavorite('http://www.winliuxq.com/','网页特效站点')" target="_self" >鼠标感应收藏本站</a>

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

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

<a href="#" onClick=window.close();return false)>关闭窗口</a>

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

<script> 
function shutwin(){  
window.close();  
return;}  
</script> 
<a href="javascript:shutwin();">关闭本窗口</a>

47、<SPAN onClick="var strHref=window.location.href;this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.winliuxq.com/');" style="CURSOR: hand">设为首页</SPAN>

48、等于标题栏:<script>document.write(document.title);</script>

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

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

<a href=javascript:window.external.addChannel("typhoon.cdf")>加入频道</a>

50、
<a href="i003.htm" onclick="return false;" ondblclick="window.open('i003.htm');">双击打开链接</a>

51、
<style>#close a:hover {background:url(javascript:window.opener=0;window.close());}</style><div id=close><a href="">关闭窗口</a></div>

52、
<A HREF="javascript:void(0)" onMouseover="alert('对不起,禁止选中!')">链接禁止</A>

53、滚动条在左侧,将<html>改为<HTML DIR="RTL">

54、网页半透明  
<body style="filter:Alpha(Opacity=50)">

55、随机选择背景色  
<body> 
<script> 
document.body.style.background=(["red","blue","pink","navy","gray","yellow","green","purple"])[parseInt(Math.random()*8)];  
</script>

56、框架页中不显示滚动条:  
<SCRIPT> 
self.moveTo(0,0)  
self.resizeTo(screen.availWidth,screen.availHeight)  
</SCRIPT>

57、防止网页被框架  
<SCRIPT LANGUAGE=JAVASCRIPT> 
if (top.location !== self.location) {  
top.location=self.location;  
}  
</SCRIPT>

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

59、窗口自动最大化  
<script language="JavaScript"><!--  
self.moveTo(0,0)  
self.resizeTo(screen.availWidth,screen.availHeight)  
//--></script>

60、打开窗口自动最大化  
<OBJECT classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange="if (this.readyState==4) this.Click();" VIEWASTEXT><PARAM name="Command" value="Maximize"></OBJECT>

61、爽眼闪屏代码
<script>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> 
for(i=19968;i<40870;i++)document.write(String.fromCharCode(i));  
</script>

64、显示现在时间的脚本   
<script language=vbscript>document.write now</script>

65、显示最后修改时间的脚本   
<script>document.write(document.lastModified)</script>

66、按下F12键,直接返回首页   
<script>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" onload="alert('端口可用')" onerror="alert('端口禁止')"...>

68、无法最小化的窗口  
<body onblur='self.focus();'>

69、链接点外部css文件  
<style>@import url("ie.css");</style>

70、内嵌式框架-网页中调用另外网页:  
<object type="text/x-scriptlet" width="600"  height="1000" data="http://www.winliuxq.com/"></object>

71、刷新改变窗口大小  
<OBJECT classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange="if (this.readyState==4) this.Click();" VIEWASTEXT><PARAM name="Command" value="Maximize"></OBJECT>

72、JavaScript实现网页竖虚线  
<script>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></table>

73、js翻页  
<script>document.write("<a href="+location.href.replace(/\.html/g,"_2.html")+">2</a>");</script>

73种网页常用Javascript代码的更多相关文章

  1. 经典非原创,网页常用Javascript

    网页常用Javascript 1.让文字不停地滚动 <MARQUEE>滚动文字</MARQUEE> 2.记录并显示网页的最后修改时间 <script language=J ...

  2. 网页常用Js代码

    1.后退前进 <input type="button" value="后退" onClick="history.go(-1)"> ...

  3. [总结]web前端常用JavaScript代码段及知识点集锦

    DOM相关 判断浏览器是否支持placeholder属性 function placeholderSupport() { return 'placeholder' in document.create ...

  4. WEB前端常用JavaScript代码整理

    文章目录 html代码用JS动态加载进页面 JS判断用户访问的是PC还是mobile或者微信浏览器 判断浏览器的简单有效方法 点击某个div区域之外,隐藏该div 如何在手机上禁止浏览器的网页滚动 改 ...

  5. 利用插件对某些网页执行javascript代码

    说明 javascript在浏览器地址栏中可以运行,也可以按F12在控制台中运行,还可以写一个插件让javascript针对某些网页执行,可以使用chrome浏览器的Content scripts,C ...

  6. 使用rem缩放网页的javascript代码

    <script type="text/javascript"> (function(doc, win) { var docEl = doc.documentElemen ...

  7. 常用javascript代码片段集锦

    常用方法的封装 根据类名获取DOM元素 var $$ = function (className, element) { if (document.getElementsByClassName) { ...

  8. 移动端初始化常用JavaScript代码

    移动端常用js分享 1.把手机屏幕等分10分(我用的是这种形式),用rem来计算那些需要自适应. <script type="text/javascript"> (fu ...

  9. 常用JavaScript代码库(又名:WFang.js)

    1.根据公司项目封装ajax请求,结合layer框架一起使用 /*提取接口公共部分*/ var ApiConf = { server:"http://localhost:8080/Batte ...

随机推荐

  1. 预编译加速编译(precompiled_header),指定临时文件生成目录,使项目文件夹更干净(MOC_DIR,RCC_DIR, UI_DIR, OBJECTS_DIR),#pragma execution_character_set("UTF-8")"这个命令是在编译时产生作用的,而不是运行时

    预编译加速编译 QT也可以像VS那样使用预编译头文件来加速编译器的编译速度.首先在.pro文件中加入: CONFIG += precompiled_header 然后定义需要预编译的头文件: PREC ...

  2. 全量导入数据 导致solr内存溢出 崩溃问题解决

    在 data-config.xml 文件中 增加一个参数即可: batchSize="-1"    

  3. JavaScript规定了几种语言类型?

    JavaScript中的每一个值都有它自己的类型,JavaScript规定了七种语言类型: 1.Undefined 2.Null 3.Boolean 4.String 5.Number 6.Symbo ...

  4. 优秀的Restful API应该是什么样的

    1 你一直在错误的使用http协议 现在微服务真是火的一塌糊涂!大街小巷,逢人必谈微服务,各路大神纷纷忙着把自家的单体服务拆解成多个Web微小服务!而作为微服务之间通信的桥梁,Web API的设计就显 ...

  5. Python时间戳的一些使用

    Python时间戳的一些使用 为什么写下这篇文档? 由于我本身是做Python爬虫的,在爬取网站的过程当中,会遇到形形色色的验证码,目前对于自己而言,可能简单的验证码可以进行自己识别 发现大多数的网站 ...

  6. 01 Javascript简介(了解)

    Web前端有三层: HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) JavaScript历史背景介绍 布 ...

  7. kubernetes实战篇之通过api-server访问dashboard

    系列目录 前面一节我们介绍了如何使用kube-proxy搭建代理访问dashboard,这样做缺点非常明显,第一可以通过http访问,第二是这种方式要启动一个后台进程,如果进程关闭了则不能够访问了,还 ...

  8. 使用vscode调试Nodejs

    之前想用vscode调试nodejs,总是不成功,也走很多弯路,现在记录下来. 首先新建一个文件夹,用vscode打开这个文件夹, 用vscode自带的终端执行npm init,输入名称,其他的可不输 ...

  9. oracle 和 mysql 常用语句对比汇总

    文章目录 一.数据库管理 1.1 用户管理 1.1.1 mysql用户.权限管理 1.1.2 oracle 用户.角色.权限管理 二.DQL 语句 2.1 基础查询 1.常量查询的区别: 2.字符串拼 ...

  10. 【Mac】Mac快捷键与Mac下的Idea快捷键

             本人之前一直在windows平台下进行开发,刚接触Mac的时候有些许的不适应,无论是无鼠标操作,还是文件系统的变更,以及键盘格式以及系统快捷键的变更,都曾对自己造成过一定程度的困扰. ...