把例如以下代码增加<body>区域中:

后退 前进

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

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

返回

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

查看源代码

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

禁止查看源代码

<body oncontextmenu="return false"></body>

刷新button一

<input type="button" value="刷新按钮一" onClick="ReloadButton()">

<script>function ReloadButton(){location.href="i001.htm";}</script>

刷新button二

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

回首页button

<input type="button" value="首页" onClick="HomeButton()">

<script>function HomeButton(){location.href=http://www.winliuxq.com/;}</script>

弹出警告框

<input type="button" value="弹出警告框" onClick="AlertButton()">

<script>function AlertButton(){window.alert("要多多光临呀。");}</script>

状态栏信息

<input type="button" value="状态栏信息" onClick="StatusButton()">

<script>function StatusButton(){window.status="要多多光临呀!

";}</script>

背景色变换

<form><input type="button" value="背景色变换" onClick="BgButton()"></form>

<script>function BgButton(){

if (document.bgColor=='#00ffff')

{document.bgColor='#ffffff';}

else{document.bgColor='#00ffff';}

}

</script>

打开新窗体

<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>

窗体最小化

<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>

全屏代码

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

关闭窗体

<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()">

最大化

<object id=big classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">

<param name="Command" value="Maximize"></object><input type=button value=最大化 onClick=big.Click()>

关闭输入法

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

链接button1

<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">

链接button2

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

链接button3

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

警告框显示源码

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

点击后button清空

<input type=button value='打印' onClick="this.style.visibility='hidden';window.print();">

打印

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

打印预览

<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)">

另存为

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

点击自己主动复制

<script>function oCopy(obj){obj.select();js=obj.createTextRange();js.execCommand("Copy")}</script>

<input type="text" value="点击自己主动复制" onClick="oCopy(this)" size="11">

自己主动选中

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

打开源码

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

新窗体延迟打开

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

实现选中文本框里的前一半的内容

<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">

点击清空文字

<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=''">

等于标题(title):

<input type="text" value="" id="aa" size="20">

<script>document.getElementById("aa").value=document.title;</script>

检測IE是否脱机

<input type="button" value="測试" onclick="alert(window.navigator.onLine)">

11种刷新button的方法

<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()">

=========================================================================================================

脚本说明:

把例如以下代码增加<body>区域中:

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

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

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

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

<a href="#" onClick=document.execCommand("print")>打印</a>

<a href="javascript:window.print();">打印</a>

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

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

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

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

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

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

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

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

<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>

<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>

<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>

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

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

<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>

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

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

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

<a href="" onMouseOver="alert('本站域名:http://www.winliuxq.com/');return true;">记住本站域名</a>

滚动栏在左側,将<html>改为<HTML DIR="RTL">

====================================================================================================

网页半透明

<body style="filter:Alpha(Opacity=50)">

随机选择背景色

<body>

<script>

document.body.style.background=(["red","blue","pink","navy","gray","yellow","green","purple"])[parseInt(Math.random()*8)];

</script>

框架页中不显示滚动栏:

<SCRIPT>

self.moveTo(0,0)

self.resizeTo(screen.availWidth,screen.availHeight)

</SCRIPT>

防止网页被框架

<SCRIPT LANGUAGE=JAVASCRIPT>

if (top.location !== self.location) {

top.location=self.location;

}

</SCRIPT>

永远都会带着框架

<script language="javascript"><!--

if (window == top)top.location.href = "frame.htm"; //frame.htm为框架网页

// --></script>

窗体自己主动最大化

<script language="JavaScript"><!--

self.moveTo(0,0)

self.resizeTo(screen.availWidth,screen.availHeight)

//--></script>

打开窗体自己主动最大化

<OBJECT classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange="if (this.readyState==4) this.Click();" VIEWASTEXT><PARAM name="Command" value="Maximize"></OBJECT>

爽眼闪屏代码

<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>

不能被另存为

<noscript><iframe src="*.html"></iframe></noscript>

汉字字库调用

<script>

for(i=19968;i<40870;i++)document.write(String.fromCharCode(i));

</script>

显示如今时间的脚本

<script language=vbscript>document.write now</script>

显示最后改动时间的脚本

<script>document.write(document.lastModified)</script>

按下F12键,直接返回首页

<script>function look(){

if(event.keyCode==123){document.location.href=http://www.winliuxq.com/}

}

if(document.onkeydown==null)

{document.onkeydown=look}

</script>

port检測

<img src="http://www.winliuxq/zza.jpg" onload="alert('port可用')" onerror="alert('port禁止')"...>

无法最小化的窗体

<body onblur='self.focus();'>

链接点外部css文件

<style>@import url("ie.css");</style>

内嵌式框架-网页中调用另外网页:

<object type="text/x-scriptlet" width="600"   height="1000" data="http://www.winliuxq.com/"></object>

刷新改变窗体大小

<OBJECT classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" onreadystatechange="if (this.readyState==4) this.Click();" VIEWASTEXT><PARAM name="Command" value="Maximize"></OBJECT>

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>

js翻页

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

JavaScript经常使用代码段的更多相关文章

  1. JavaScript代码段整理笔记系列(二)

    上篇介绍了15个常用代码段,本篇将把剩余的15个补齐,希望对大家有所帮助!!! 16.检测Shift.Alt.Ctrl键: event.shiftKey; //检测Shift event.altKey ...

  2. 《超实用的JavaScript代码段》—— 读后总结

    这本书全是代码,从头到尾跟着坐下来确实收获很多.比那些古板的教科书式的理解更多,不过书中并不是每个例子都做了,有的作者封装的太多,觉得看了收获不多,就没细看——比如模块渐变.有空好好学学这段的代码. ...

  3. 前端福利!10个短小却超实用的JavaScript 代码段

    JavaScript正变得越来越流行,它已经成为前端开发的第一选择,并且利用基于JavaScript语言的NodeJS,我们也可以开发出高 性能的后端服务,甚至我还看到在硬件编程领域也出现了JavaS ...

  4. chrome小书签-实用的小功能-javascript代码段

    1.打印页面的所有脚本引用文件及代码段: javascript:var scriptarray=document.getElementsByTagName("script");fo ...

  5. C# 代码中调用 Javascript 代码段以提高应用程序的配置灵活性(使用 Javascript .NET 与 Jint)

    一般来说,我们需要在开发应用软件的配置文件中,添加一些参数,用于后续用户根据实际情况,自行调整. 配置参数,可以放在配置文件中.环境变量中.或数据库表中(如果使用了数据库的话).通常,配置数据,以 k ...

  6. 【摘】50个jQuery代码段帮助你成为一个更好的JavaScript开发者

    今 天的帖子会给你们展示50个jQuery代码片段,这些代码能够给你的JavaScript项目提供帮助.其中的一些代码段是从jQuery1.4.2才 开始支持的做法,另一些则是真正有用的函数或方法,他 ...

  7. 推荐10 个短小却超实用的 JavaScript 代码段

    1. 判断日期是否有效 JavaScript中自带的日期函数还是太过简单,很难满足真实项目中对不同日期格式进行解析和判断的需要.jQuery也有一些第三方库来使日期相关的处理变得简单,但有时你可能只需 ...

  8. 十五个常用的jquery代码段【转】

    好的文章顶一个 回到顶部按钮 通过使用 jQuery 中的 animate 和 scrollTop 方法,你无需插件便可创建一个简单地回到顶部动画: 1 // Back to top 2 $('a.t ...

  9. 十五个常用的jquery代码段

    十五个常用的jquery代码段 回到顶部按钮 通过使用 jQuery 中的 animate 和 scrollTop 方法,你无需插件便可创建一个简单地回到顶部动画: 1 // Back to top ...

随机推荐

  1. luogu P2254 [NOI2005]瑰丽华尔兹

    题目链接 luogu P2254 [NOI2005]瑰丽华尔兹 题解 为什么我我我不放放放bzoj的链接呢? 因为打的暴力啊,然后bzojT了呀QAQQQQQ(逃 然后luogu竟然过了呀呀呀 dp[ ...

  2. 【20181019T2】硬币【矩阵快速幂优化DP】

    题面 [错解] 哎\(N \leq 50\)?双向搜索? 切了切-- 等下,好像要求方案数-- 好像搜不了 哎他给\(V_{i} | V_{i+1}\)干嘛? 肯定有用啊 为了体现条件的用处,我在搜下 ...

  3. HDU 6039 Gear Up(线段树+并查集)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6039 [题目大意] 给出一些齿轮,有些齿轮是边相连,也就是拥有相同的线速度, 有的齿轮是轴相连,也 ...

  4. 深度学习的GDB调试命令和经验记录

    调试的指令很简单: cd $CAFFE_ROOT, 1. gdb ./build/tools/caffe 2. 设置运行参数 set args train --solver=xxxxsolver.pr ...

  5. [bzoj1012](JSOI2008)最大数maxnumber(Fenwick Tree)

    Description 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. 2. ...

  6. HttpClient中文乱码问题排查

    可以尝试一下方法解决: 1. httpPost.setHeader("Content-Type", "application/json; charset=UTF-8&qu ...

  7. WPF Interaction框架简介(一)——Behavior

    在WPF 4.0中,引入了一个比较实用的库——Interactions,这个库主要是通过附加属性来对UI控件注入一些新的功能,除了内置了一系列比较好用的功能外,还提供了比较良好的扩展接口.本文这里简单 ...

  8. ajax跨域的解决方案

    前言 公司要做一个活动页面,在其过程中发现所有的接口,ajax请求跨域.这里对跨域做个简单介绍以及提供几种解决办法. 由于浏览器实现的同源策略的限制,XmlHttpRequest只允许请求当前源(域名 ...

  9. mybatis查询日期时间数据得到long类型数据的问题

    使用mybatis查询数据时,如果数据库存储的是timestamp.datetime.date.time等时间类型,而Java bean也使用的是date类型,mybatis会自动将date类型转换为 ...

  10. [Android Pro] 获取手机已经安装的应用 和 获取当前正在运行的所有进程(一个uid对应多个pid)

    1: 获取PackageManager 获取全部静态已安装的应用: PackageManager pm = getPackageManager(); List<PackageInfo> i ...