网页常用Js代码
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>
functionHomeButton(){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.ope('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/')",1 0000)>
26、实现选中文本框里的前一半的内容
<input type="text" value="选中文本框里的前一半的内容" size=30 onmouseover="this.select();tR=document.selection.createRange();tR.moveE nd('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,loca tion=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.setHomeP age('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="varstrHref=window.location.href;this.style.behavior='url(#default#homepage)';t his.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、随机选择背景色
<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="text/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>
网页常用Js代码的更多相关文章
- 73种网页常用Javascript代码
73种网页常用Javascript代码 转载自:前端丶灵魂工程师 1.后退 前进 <input type="button" value="后退" o ...
- 常用JS代码片段
1.隐藏部分数字,如手机号码,身份证号码 1 2 3 function (str,start,length,mask_char){ return str.replace(str.substr(star ...
- 站长常用的200个js代码 站长常用js代码大全 站长常用js代码集合
站长常用的200个js代码 1.文本框焦点问题 onBlur:当失去输入焦点后产生该事件 onFocus:当输入获得焦点后,产生该文件 Onchange:当文字值改变时,产生该事件 Onselect: ...
- 常用js代码整理、收集
个人整理了一下个人常用到的一些js代码,以方便学习以及日后使用,或许有一些是个人之前从网上摘下来的,但是不记得是具体从哪里来的了,如果你看到有一段代码跟你的文章很相似甚至一样,请不要气愤,请告诉我,我 ...
- 自动化测试-20.selenium常用JS代码执行
前言: 在工作中有些控件定位不到,需要操作,使用JS代码去修改或者操作达到selenium不能做的操作. 1.Web界面的滑动 1 #coding:utf-8 2 from selenium impo ...
- 右键查看别人网页的js代码为什么会显示乱码
查看别人网页的js显示乱码 解决方法: 打开浏览器,选择设置,点击更多,选择文字编码为Unicode
- 常用js代码学习
1.用JS实现的radio图片选择按钮效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...
- 100个常用js代码(转载)
作者:小萧ovo链接:https://zhuanlan.zhihu.com/p/23076321来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. JavaScript定点 ...
- !!!常用JS代码块 (jquery)
jquery代码块 <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> ...
随机推荐
- C#面向对象基本概念总结
快过年了,发一篇自己的复习总结.以下内容均是个人理解,如文章有幸被浏览,如有错误的地方欢迎大家提出,相互学习相互进步! 面向对象三大基本特征:封装,继承,多态 一.类 (对象声明的三种方式:以普通基类 ...
- 2019年6月pmp考试马上开始!报考9月怎么进行中文报名?
2019年6月pmp考试马上开始了,现在还可不可以报名参加考试呢?来不来得及呢?怎么进行中文报名,考点在哪里?如果现在想报考9月怎么进行中文报名?下面慧翔天地就给大家分享! (关于甘特图的画法,项目管 ...
- 【游戏开发】基于VS2017的OpenGL开发环境搭建
一.简介 最近,马三买了两本有关于“计算机图形学”的书籍,准备在工作之余鼓捣鼓捣图形学和OpenGL编程,提升自己的价值(奔着学完能涨一波工资去的).俗话说得好,“工欲善其事,必先利其器”.想学习图形 ...
- JGUI源码:组件及函数封装方法(7)
以Accordion为例1.在base.js定义一个对象,这样可以和JQuery对象区分开,用户使用组件时比较清晰一点,也可以在这里引用多个库. var JGUI = J = { version : ...
- ioctl函数
一.函数原型 #include <unistd.h> int ioctl(int fd, int request, .../* void *arg */); 二.和网络相关的请求(requ ...
- Promise库
标准 https://promisesaplus.com/ An open standard for sound, interoperable JavaScript promises—by imple ...
- kali linux工具--信息批量收集工具theharvester
在渗透测试早期阶段,安全人员往往需要从互联网快速获取目标的一些信息,以确认测试目标的概况.为了满足这个需求,Kali Linux提供了theharvester工具.该工具可以搜索引擎.社交网站获取目标 ...
- docker学习------centos7.5下的swarm集群可视化构建
1.swarm集群 manager : 192.168.211.175 agent1 : 192.168.211.176 agent2 : 192.168.211.177 2.环境 ...
- TERADATA SQL学习随笔<一>
此博客内容简介及目录 http://www.cnblogs.com/weibaar/p/6644261.html 最近在TERADATA环境学习SQL.在这里记录一下学习中查过的知识点,作为备案. 目 ...
- KVO实现原理
KVO意为键值观察Key-Value-Observer,本质仍然是观察者模式. 观察者模式的定义:一个目标对象管理所有依赖于它的观察者对象,并在它自身的状态改变时主动通知观察者对象.这个主动通知通常是 ...