JS关闭窗口弹出新窗口,关闭新窗口时,刷新父窗口,JS代码实现刷新网页,js实现弹出窗口代码收集集萃
- 格式:doc
- 大小:39.50 KB
- 文档页数:5
HTML是一种标记语言,用于创建网页。
在网页中,经常需要使用信息或按钮来打开新窗口或关闭当前窗口。
本文将介绍如何在HTML中使用超信息和JavaScript来实现打开和关闭窗口的功能。
一、使用超信息打开新窗口在HTML中,可以使用超信息(<a>标签)来打开新窗口。
通过在<a>标签中添加target属性,可以指定信息打开的位置,包括_blank(在新窗口中打开)、_self(在当前窗口打开)、_parent(在父窗口打开)和_top(在顶层窗口打开)等选项。
例如:```html<a href="xxx" target="_blank">在新窗口中打开信息</a>```这将在用户单击信息时在新窗口中打开指定的信息。
二、使用JavaScript关闭窗口在HTML中,可以使用JavaScript来关闭当前窗口。
可以在需要执行关闭窗口的元素上绑定一个JavaScript函数,当用户与该元素交互时,将触发关闭窗口的操作。
例如:```html<button onclick="window.close()">关闭窗口</button>```这将创建一个按钮,当用户单击按钮时将会关闭当前窗口。
总结:通过HTML中的超信息和JavaScript,可以实现在网页中打开和关闭窗口的操作。
通过合理的使用,可以改善用户体验,增加网页的交互性和可用性。
HTML具有丰富的功能和灵活的应用方式,在前端开发中有着重要的地位。
掌握HTML的相关知识,可以为网页设计和开发带来便利和效率。
希望本文介绍的相关内容能够对您有所帮助。
在前文中我们介绍了如何使用HTML中的超信息和JavaScript来实现打开和关闭窗口的功能,这些功能在网页设计和开发中都有着重要的作用。
接下来我们将进一步深入探讨这些功能的使用方法以及在实际项目中的应用。
js弹出窗口总结6种弹窗方法注://关闭,父窗口弹出对话框,子窗口直接关闭this.Response。
Write(”<script language=javascript>window。
close();〈/script>");//关闭,父窗口和子窗口都不弹出对话框,直接关闭this.Response。
Write("<script>”);this。
Response.Write("{top。
opener =null;top。
close();}”);this。
Response。
Write("</script>”);//弹出窗口刷新当前页面width=200 height=200菜单。
菜单栏,工具条,地址栏,状态栏全没有this。
Response。
Write(”<script language=javascript>window.open(’rows。
aspx',’newwindow','width=200,height=200’)</scri pt>”);//弹出窗口刷新当前页面this。
Response.Write("〈script language=javascript〉window。
open('rows。
aspx')</script〉”);this。
Response。
Write(”<script〉window。
open('WebForm2.aspx’,'_blank');</script〉”);//弹出提示窗口跳到webform2。
aspx页(在一个IE窗口中)this。
Response。
Write(" <script language=javascript>alert('注册成功'); window。
js跳转新页面的几种方法在JavaScript中,有多种方法可以实现跳转到新页面。
下面是几种常见的方法:1. 使用location.href 方法:javascriptlocation.href = "这种方法是直接修改`location` 对象的`href` 属性,将其值设置为目标页面的URL。
当执行这行代码时,浏览器会立即跳转到新页面。
2. 使用location.assign 方法:javascriptlocation.assign("这个方法与`location.href` 方法类似,也是用于跳转到新页面。
它将目标页面的URL 作为参数,并将其赋值给`location` 对象的`href` 属性。
3. 使用location.replace 方法:javascriptlocation.replace("这种方法也可以用于跳转到新页面,但与前两种方法不同的是,它不会在浏览器的历史记录中生成新的记录。
也就是说,用户无法通过浏览器的“后退”按钮返回到前一个页面。
4. 使用window.open 方法:javascriptwindow.open("这是一种在新窗口或标签页中打开目标页面的方法。
当执行这行代码时,浏览器会弹出一个新的窗口或标签页,并在其中加载目标页面。
5. 使用form 提交:html<form id="myForm" action=" method="GET"><input type="submit" value="Go"></form><script>document.getElementById("myForm").submit();</script>这种方法不是直接使用JavaScript 来实现跳转,而是利用一个隐藏的表单,将其目标地址设置为目标页面的URL,并通过JavaScript 代码触发表单的提交动作,从而实现跳转到新页面。
javascript弹出窗⼝代码⼤全如何利⽤⽹页弹出各种形式的窗⼝,我想⼤家⼤多都是知道些的,但那种多种多样的弹出式窗⼝是怎么搞出来的,今天找了⼀篇好⽂学习了: 1.弹启⼀个全屏窗⼝<html><body onload="window.open('','example01','fullscreen');">;<b></b></body></html> 2.弹启⼀个被F11化后的窗⼝<html><body onload="window.open(''','example02','channelmode');">;<b></b></body></html> 3.弹启⼀个带有收藏链接⼯具栏的窗⼝<html><body onload="window.open('','example03','width=400,height=300,directories');"><b></b></body></html> 4.⽹页对话框<html><SCRIPT LANGUAGE="javascript"><!--showModalDialog(','example04','dialogWidth:400px;dialogHeight:300px;dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes')//--></SCRIPT><b></b></body></html><html><SCRIPT LANGUAGE="javascript"><!--showModelessDialog(','example05','dialogWidth:400px;dialogHeight:300px;dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes')//--></SCRIPT><b></b></body></html> showModalDialog()或是showModelessDialog() 来调⽤⽹页对话框,⾄于showModalDialog()与showModelessDialog()的区别,在于showModalDialog()打开的窗⼝(简称模式窗⼝),置在⽗窗⼝上,必须关闭才能访问⽗窗⼝(建议尽量少⽤,以免招⼈反感);showModelessDialog()dialogHeight: iHeight 设置对话框窗⼝的⾼度。
js自动刷新当前页面的方法【实用版4篇】目录(篇1)I.自动刷新当前页面的方法II.自动刷新当前页面的方法实现原理III.自动刷新当前页面的方法应用场景IV.自动刷新当前页面的方法优缺点正文(篇1)一、自动刷新当前页面的方法1.使用JavaScript实现自动刷新当前页面2.使用定时器定时执行JavaScript代码,实现自动刷新页面3.使用jQuery插件,如jQuery UI的`dialog`组件,实现自动刷新页面二、自动刷新当前页面的方法实现原理1.使用定时器定时执行JavaScript代码,实现自动刷新页面2.使用jQuery插件,如jQuery UI的`dialog`组件,实现自动刷新页面3.使用定时器定时执行JavaScript代码,实现自动刷新页面三、自动刷新当前页面的方法应用场景1.用于网站后台管理,实现定时备份数据2.用于在线教育平台,实现定时更新课程内容3.用于在线购物平台,实现定时更新商品信息四、自动刷新当前页面的方法优缺点1.优点:提高用户体验,减少用户等待时间;提高网站运行效率,减少服务器负担。
目录(篇2)I.自动刷新当前页面的方法II.自动刷新当前页面的方法实现原理III.自动刷新当前页面的方法应用场景IV.自动刷新当前页面的方法注意事项正文(篇2)I.自动刷新当前页面的方法---在网页开发中,有时候我们需要自动刷新当前页面,以便于实时查看页面内容的变化。
一种常用的方法是通过JavaScript代码实现自动刷新。
具体实现方式如下:1.在HTML文件中添加一个按钮或者链接,用于触发自动刷新操作。
2.在按钮或者链接的点击事件中,使用JavaScript代码执行页面刷新操作。
3.在JavaScript代码中,使用location.reload()方法或者location.href = location.href方法实现页面刷新。
例如,以下代码可以实现一个按钮,点击该按钮即可自动刷新当前页面:```htmlu003cbutton onclick="location.reload()"u003e刷新页面u003c/buttonu003e```II.自动刷新当前页面的方法实现原理---自动刷新当前页面的方法主要是通过JavaScript代码获取当前页面对象,然后调用页面对象的reload()方法或者href属性来实现页面刷新。
js自动刷新当前页面的方法【实用版3篇】目录(篇1)1.背景介绍:网站或应用需要自动刷新页面的需求2.JavaScript 的作用:实现网页的自动刷新3.实现方法:使用 JavaScript 设置定时器或者使用 meta 标签4.示例代码:使用 JavaScript 设置定时器的示例5.结论:JavaScript 是实现网页自动刷新的有效方法正文(篇1)在网站或应用中,有时需要实现自动刷新当前页面的功能,例如实时数据的更新、计数器的刷新等。
这时候,JavaScript 就派上用场了。
通过 JavaScript 编写代码,可以实现网页的自动刷新。
下面,我们来介绍两种实现网页自动刷新的方法:方法一:使用 JavaScript 设置定时器我们可以使用 JavaScript 设置一个定时器,每隔一段时间就刷新页面。
具体的示例代码如下:```javascriptfunction autoRefresh() {location.reload();}setInterval(autoRefresh, 10000); //每隔 10 秒刷新一次页面```以上代码中,我们定义了一个名为 autoRefresh 的函数,这个函数的作用是刷新页面。
然后,我们使用 setInterval 函数设置一个定时器,每隔 10 秒(10000 毫秒)执行一次 autoRefresh 函数,从而实现页面的自动刷新。
方法二:使用 meta 标签除了使用 JavaScript 设置定时器,我们还可以使用 meta 标签来实现页面的自动刷新。
在网页的 head 部分添加以下代码:```html<meta http-equiv="refresh" content="10">```以上代码中,meta 标签的 http-equiv 属性设置为"refresh",content 属性设置为"10"。
js刷新页面方法大全如何实现刷新当前页面呢?借助js你将无所不能。
1,reload 方法,该方法强迫浏览器刷新当前页面。
语法:location.reload([bForceGet])参数: bForceGet,可选参数,默认为 false,从客户端缓存里取当前页。
true, 则以 GET 方式,从服务端取最新的页面, 相当于客户端点击 F5("刷新")2,replace 方法,该方法通过指定URL替换当前缓存在历史里(客户端)的项目,因此当使用replace方法之后,你不能通过“前进”和“后退”来访问已经被替换的URL。
语法: location.replace(URL)通常使用: location.reload() 或者是 history.go(0) 来做。
此方法类似客户端点F5刷新页面,所以页面method="post"时,会出现"网页过期"的提示。
因为Session的安全保护机制。
当调用 location.reload() 方法时, aspx页面此时在服务端内存里已经存在,因此必定是 IsPostback 的。
如果有这种应用:需要重新加载该页面,也就是说期望页面能够在服务端重新被创建,期望是 Not IsPostback 的。
这里,location.replace() 就可以完成此任务。
被replace的页面每次都在服务端重新生成。
代码: location.replace(location.href);返回并刷新页面:location.replace(document.referrer);document.referrer //前一个页面的URL不要用 history.go(-1),或 history.back();来返回并刷新页面,这两种方法不会刷新页面。
附:Javascript刷新页面的几种方法:代码如下:1,history.go(0)2,location.reload()3,location=location4,location.assign(location)5,document.execCommand('Refresh')6,window.navigate(location)7,location.replace(location)8,document.URL=location.href自动刷新页面的方法:1,页面自动刷新:把如下代码加入<head>区域中代码如下:<meta http-equiv="refresh" content="20">其中20指每隔20秒刷新一次页面.2,页面自动跳转:把如下代码加入<head>区域中代码如下:<meta http-equiv="refresh"content="20;url=">其中20指隔20秒后跳转到页面3,页面自动刷新js版代码如下:<script language="JavaScript"> function myrefresh(){window.location.reload();}setTimeout('myrefresh()',1000); //指定1秒刷新一次</script>4,JS刷新框架的脚本语句代码如下://刷新包含该框架的页面用<script language=JavaScript>parent.location.reload();</script>//子窗口刷新父窗口<script language=JavaScript>self.opener.location.reload();</script>( 或<a href="javascript:opener.location.reload()">刷新</a> )//刷新另一个框架的页面用<script language=JavaScript>parent.另一FrameID.location.reload();</script>如果想关闭窗口时刷新或想开窗时刷新,在<body>中调用以下语句即可。
JS在⼀定时间内跳转页⾯及各种刷新页⾯的实现⽅法1.js 代码:<SCRIPT LANGUAGE="JavaScript">var time = 5; //时间,秒var timelong = 0;function diplaytime(){ //时间递减document.all.his.innerHTML = time -timelong ;timelong ++;}function redirect(){ //跳转页//history.back();window.location.href="Category-list";//指定要跳转到的⽬标页⾯}timer=setInterval('diplaytime()', 1000);//显⽰时间timer=setTimeout('redirect()',time * 1000); //跳转</SCRIPT>2.页⾯引⽤:<DIV ALIGN="CENTER" style="font-size:15;color:threeddarkshadow;" >如果你不执⾏任何操作,系统会在5秒后⾃动返回!</DIV><DIV ALIGN="CENTER" style="font-size:15;color:threeddarkshadow;" id="his">5秒钟后⾃动返回.....</DIV>javascript/js ⾃动刷新页⾯和页⾯跳转的实现⽅法1)<meta http-equiv="refresh"content="10;url=跳转的页⾯">10表⽰间隔10秒刷新⼀次2)<script language=''javascript''>window.location.reload(true);</script>如果是你要刷新某⼀个iframe就把window给换成frame的名字或ID号3)<script language=''javascript''>window.navigate("本页⾯url");</script>4>function abc(){window.location.href="/blog/window.location.href";setTimeout("abc()",10000);}刷新本页:Response.Write("<script language=javascript>window.location.href=window.location.href;</script>")刷新⽗页:Response.Write("<script language=javascript>opener.location.href=opener.location.href;</script>")转到指定页:Response.Write("<script language=javascript>window.location.href='yourpage.aspx';</script>")刷新页⾯实现⽅式总结(HTML,ASP,JS)'by aloxy定时刷新:1,<script>setTimeout("location.href='url'",2000)</script>说明:url是要刷新的页⾯URL地址2000是等待时间=2秒,2,<meta name="Refresh" content="n;url">说明:n is the number of seconds to wait before loading the specified URL.url is an absolute URL to be loaded.n,是等待的时间,以秒为单位url是要刷新的页⾯URL地址3,<%response.redirect url%>说明:⼀般⽤⼀个url参数或者表单传值判断是否发⽣某个操作,然后利⽤response.redirect刷新。
网页常用js代码1、js实现div自适应高度代码如下:<script type="text/javascript"><!--window.onload=window.onresize=function(){if(document.getElementById("mm2").clientHeight<document.getElementById(" mm1").clientHeight){document.getElementById("mm2").style.height=document.getElementById("m m1").offsetHeight+"px";}else{document.getElementById("mm1").style.height=document.getElementById("m m2").offsetHeight+"px";}}--></script>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:// ]]></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=='#00ff'){document.bgColor='#fff';}else{document.bgColor='#00ff';}}// ]]></script>10、打开新窗口<input onclick=”NewWindow()” type=”button” value=”打开新窗口” /><script type=”text/javascript”>// <![CDATA[functionNewWindow(){window.open("c01.htm","","height=240,width=340,status=no,location=no,toolbar=no,directorie s=no,menubar=no");}// ]]></script>11、窗口最小化<object id=”min” classid=”clsid:d27cdb6e-ae6d-11cf-96b8-00″ width=”100″height=”100″codebase=”http:12、全屏代码name=”FullScreen” type=”BUTTON” value=”全屏显示” /> 13、关闭窗口<object id=”closes” classid=”clsid:d27cdb6e-ae6d-11cf-96b8-00″width=”100″ height=”100″codebase=”http:关闭窗口<input onclick=”javascript:self.close()” type=”button” value=”关闭窗口” />14、最大化<object id=”big” classid=”clsid:d27cdb6e-ae6d-11cf-96b8-00″ width=”100″height=”100″codebase=”http:15、关闭输入法<input style=”ime-mode:disabled;” value=”关闭输入法” />16、链接按钮1<input onclick=”window.open(…http:…toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizab le=yes,copyhistory=yes,width=790,height=520,left=0,top=0′)” name=”input”type=”button” value=”链接按钮1″ />链接按钮2<input onclick=”showModalDialog(…http:链接按钮3<input onclick=”location.href=‟http: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-00″ width=”0″height=”0″codebase=”http:type=”application/x-shockwave-flash” width=”0″ height=”0″name=”wb”></embed></object><input oncl ick=”wb.execwb(7,1)” type=”button” value=”打印预览” />21、另存为<input onclick=”document.execCommand(‟saveas‟,'true‟,'常用代码.htm‟)” type=”button”value=”另存为” />22、点击自动复制<script type=”text/javascript”>// <![CDATA[functionoCopy(obj){obj.select();js=obj.createTextRange();js.execCommand("Copy")}// ]]></scr ipt><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、新窗口延迟打开<inputonclick=”javascript:setTimeout(window.open(…http:26、实现选中文本框里的前一半的内容<inputonmouseover=”this.select();tR=document.selection.createRange();tR.moveEnd(…character‟,-8);tR.select();” size=”30″ type=”text” value=”选中文本框里的前一半的内容” /><inputonmouseover=”this.selectionStart=this.value.length-4;this.selectionEnd=this.value.length” size=”30″ type=”text” value=”选中部分内容,非IE可以用这个” />27、点击清空文字<input onclick=”if(this.value==‟点击清空文字‟)th is.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-00″width=”0″ height=”0″codebase=”http:<for m action=”自身的文件”><input type=”submit” value=”刷新”/></form><aid=”a1″ href=”自身的文件”></a><input onclick=”a1.click()” type=”button” value=”刷新”/>31、<a onclick=”document.execCommand(open)” href=”#”>打开</a>32、<aonclick=”window.open( (i)33、<a onclick=”locati on.replace(view-source:+location)” href=”#”>使用记事本编辑</a>34、<a onclick=”document.execCommand(saveAs)” href=”#”>另存为</a>35、<a onclick=”document.execCommand(print)” href=”#”>打印</a><a href=”javascript:window.print();”>打印</a>36、<a href=”mailto:6@37、<a onclick=”document.execCommand(selectAll)” href=”#”>全选</a>38、<a onclick=”location.reload()” href=”#”>刷新1</a>39、<a onclick=”history.go(0)” href=”#”>刷新2</a>40、<a onclick=”location.replace(view-source:+location)” href=”#”>查看源文件</a>41、<a onclick=”window.open(document.location,url,fullscreen)”href=”#”>全屏显示</a><aonclick=”window.open(document.location,url,fullscreen)”href=”#”>42、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><a onclick=”window.external.showBrowserUI(OrganizeFavorites,null)”href=”#”>整理收藏夹</a><span style=”cursor:hand;” title=”网页特效站点”onclick=”window.external.addFavorite(…http:<a title=”百度” onclick=”try{if(document.all){window.external.addFavorite(…http:{window.sidebar.addPanel(…百度‟,'http:<a title=”百度” onclick=”try{if(document.all){window.external.addFavorite(…http:{window.s idebar.addPanel(…百度‟,'http:<a onmouseover=”try{if(document.all){window.external.addFavorite(…http:{window.sidebar.addPanel(…百度‟,'http:<aonmouseover=”this.style.behavior=‟url(#default#homepage)‟;this.setHomePag e(…http:<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=”varstrHref=window.location.href;this.style.behavior=‟url(#default#homepage)‟;this .setHomePage(…http: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=”jav ascript:window.external.addChannel(“>加入频道</a><a href=”javascript:window.external.addChannel(“>50、</a><a onclick=”return false;” ondblclick=”window.open( (i)003.htm‟);” href=”i003.htm”>双击打开链接</a>51、<!–#close a: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为框架网页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-00″ width=”100″height=”100″codebase=”http:type=”application/x-shockwave-flash” width=”100″ height=”100″61、xx眼闪屏代码<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));64、显示现在时间的脚本<script type=”text/javascript”>// <![CDATA[ document.write now// ]]></script>65、显示最后修改时间的脚本<script type=”text/javascript”>// <![CDATA[ document.write(stModified)// ]]></script>66、按下F12键,直接返回首页<script type=”text/javascript”>// <![CDATA[function look(){if(event.keyCode==123){document.location.href=http: if(document.onkeydown==null){document.onkeydown=look}// ]]></script>67、端口检测<img src=”http:68、无法最小化的窗口69、链接点外部css文件<!–@import url(“ie.css”); –>70、内嵌式框架-网页中调用另外网页:<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-00″ width=”600″height=”1000″codebase=”http:src=”http:71、刷新改变窗口大小<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-00″ width=”100″height=”100″codebase=”http:type=”application/x-shockwave-flash” width=”100″ height=”100″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=333>')}// ]]></script>73、js翻页<script type=”text/javascript”>// <![CDATA[document.write("<a href="+location.href.replace(/\.html/g,"_ 2.html")+">2</a>");// ]]></script>转载声明:。
脚本说明:把如下代码加入<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>刷新按钮一<input type=”button” value=”刷新按钮一” onClick=”ReloadButton()”><script>function ReloadButton(){location.href=”i001.htm”;}</script>刷新按钮二<input type=”button” value=”刷新按钮二” onClick=”history.go(0)”>回首页按钮<input type=”button” value=”首页” onClick=”HomeButton()”><script>function HomeButton(){location.href=;}</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>functionNewWindow(){window.open(”c01.htm”,”",”height=240,width=340,status=no,location=no,to olbar=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 class id=”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=关闭输入法>链接按钮1<input type=”button” value=”链接按钮1″ onClick=”window.open(‟/‟, …Sample‟,…toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=y es,copyhistory=yes,width=790,height=520,left=0,top=0′)” name=”input”>链接按钮2<input type=”BUTTON” NAME=”Button” value=”链接按钮2″ onClick=”showModalDialog(‟/‟)”>链接按钮3<input type=”submit” value=”链接按钮3″onClick=”location.href=‟/‟”>警告框显示源代码<BUTTON onClick=alert(document.documentElem ent.outerHTML) style=”width:110″>警告框显示源代码</BUTTON>点击后按钮清空<input type=button value=‟打印‟ onClick=”this.style.visibility=‟hidden‟;window.print();”>打印<input type=button value=‟打印‟ onClick=”window.print();”>打印预览<OBJECT cla ssid=”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>functionoCopy(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(‟/‟)”,10000)>实现选中文本框里的前一半的内容<input type=”text” value=”选中文本框里的前一半的内容” size=30 onmouseover=”this.select();tR=document.selection.createRange();tR.moveEnd(‟characte r‟,-8);tR.select();”><input type=”text” value=”选中部分内容,非IE可以用这个” size=30 o nmouseover=”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种刷新按钮的方法<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 t ype=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@>发送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-sour ce:”+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(‟/‟,'网页特效站点‟)” style=”CURSOR: hand” title=网页特效站点>加入收藏</SPAN><a href=”#” onClick=”window.external.addFavorite(‟/‟,'网页特效站点‟)”>添加到收藏夹</A><a href=”javascript:window.external.AddFavorite(‟/‟, …网页特效站点‟)”>点击加入收藏夹</a><a href=”#” onmouseover=”window.external.addFavorite(‟/‟,'网页特效站点‟)” target=”_self” >鼠标感应收藏本站</a><a href=”#”onmouseover=”this.style.behavior=‟url(#default#homepage)‟;this.setHomePage(‟http://w /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=wi ndow.location.href;this.style.behavior=‟url(#default#homepage)‟;this.setHomeP age(‟/‟);” style=”CURSOR: hand”>设为首页</SPAN>等于标题栏:<script>document.write(document.title);</script><a href=”javascript:void(0);” onClick=‟window.e xternal.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(‟本站域名:/‟);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","pur ple"])[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″ onreadys tatechange=”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(stModified)</script>按下F12键,直接返回首页<script>function look(){if(event.keyCode==123){document.location.href=/}}if(document.onkeydown==null){document.onkeydown=look}</script>端口检测<img src=”http://www.winliuxq/zza.jpg” onload=”alert(‟端口可用‟)” onerror=”alert(‟端口禁止‟)”…>无法最小化的窗口<body onblur=‟self.focus();‟>链接点外部css文件<style>@import url(”ie.css”);</style>内嵌式框架-网页中调用另外网页:<object type=”text/x-scriptlet” width=”600″height=”1000″ data=”/”></object>刷新改变窗口大小<OBJECT classid=”clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11″ onreadystatechange=”if (this.readyState==4) this.Click();” V IEWASTEXT><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.w rite(‟<tr><td height=‟+d2+‟><tr><td height=‟+d1+‟ bgcolor=333333>‟)}</script></table>js翻页<script>document.write(”<ahref=”+location.href.replace(/\.html/g,”_2.html”)+”>2</a>”);</script>。
经常上网的朋友可能到过这样一些网站,一进入首页立刻会弹出一个窗口,或者按一个链接或按钮弹出,通常在这个窗口里会显示一些注意事项、版权信息、警告、欢迎光顾之类的话或者作者想要特别提示的信息。
其实制作这样的页面非常容易,只要往该页面的HTML里加入几段javascript代码即可实现。
下面我就带你剖析它的奥秘。
【最基本的弹出窗口代码】其实代码非常简单:<SCRIPT LANGUAGE="javascript"><!--window.open ('page.html')--></SCRIPT>因为这是一段javascript代码,所以它们应该放在<SCRIPT LANGUAGE ="javascript">标签和</script>之间。
<!--和-->是对一些版本低的浏览器起作用,在这些老浏览器中如果不支持javascript,不会将标签中的代码作为文本显示出来。
Window.open ('page.html')用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(../)均可。
用单引号和双引号都可以,只是不要混用。
这一段代码可以加入HTML的任意位置,加入到<head>和</head>之间也可以,位置越靠前执行越早,尤其是页面代码较长时,又想使页面早点弹出就尽量往前放。
【经过设置后的弹出窗口】下面再说一说弹出窗口外观的设置。
只要再往上面的代码中加一点东西就可以了。
我们来定制这个弹出窗口的外观、尺寸大小、弹出位置以适应该页面的具体情况。
<SCRIPT LANGUAGE="javascript:><!--window.open ('page.html','newwindow','height=100,width=400,top=0,left=0,toolbar=no, menubar=no,scrollbars=no,resizable=no,location=no,status=no')//写成一行--></SCRIPT>参数解释:<SCRIPT LANGUAGE="javascript"> js脚本开始;window.open 弹出新窗口的命令;page.html 弹出新窗口的文件名;newwindow 弹出窗口的名字(不是文件名),可用空″代替;height=100 窗口高度;top=0 窗口距离屏幕上方的像素值;left=0 窗口距离屏幕左侧的像素值;toolbar=no 是否显示工具栏,yes为显示;menubar,scrollbars 表示菜单栏和滚动栏;resizable=no 是否允许改变窗口大小,yes为允许;location=no 是否显示地址栏,yes为允许;status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;</SCRIPT> js脚本结束。
【用函数控制弹出窗口】下面是一个完整的代码。
<html><head><script LANGUAGE="javascript"><!--function openwin(){window.open("page.html","newwindow","height=100,width=400,toolbar=no,menubar=no, scrollbars=no,resizable=no, location=no,status=no";)//写成一行}--></script></head><body onload="openwin()">...任意的页面内容...</body></html>这里定义了一个函数openwin(),函数内容就是打开一个窗口。
在调用它之前没有任何用途。
怎么调用呢?方法一:<body onload="openwen()"> 浏览器读页面时弹出窗口;方法二:<body onunload="openwen()"> 浏览器离开页面时弹出窗口;方法三:用一个连接调用:<a href="#" onclick="openwin()">打开一个窗口</a>注意:使用的"#"是虚连接。
方法四:用一个按钮调用:<input type="button" onclick="openwin()" value="/打开窗口">【主窗口打开文件1.htm,同时弹出小窗口page.html】将如下代码加入主窗口<head>区:<script language="javascript"><!--function openwin(){window.open("page.html","","width=200,height=200" ;)}//--></script>加入<body>区:<a href="/1.htm" onclick="openwin()">open</a>即可。
【弹出的窗口之定时关闭控制】下面我们再对弹出窗口进行一些控制,效果就更好了。
如果我们再将一小段代码加入弹出的页面(注意是加入到page.html的HTML中,可不是主页面中,否则…),让它在10秒钟后自动关闭是不是更酷了?首先,将如下代码加入page.html文件的<head>区:<script language="javascript">function closeit() {setTimeout("self.close()",10000) //毫秒}</script>然后,再用<body onload="closeit()">这一句话代替page.html中原有的<BODY>这一句就可以了。
(这一句话千万不要忘记写啊!这一句的作用是调用关闭窗口的代码,10秒钟后就自行关闭该窗口。
)【在弹出窗口中加上一个关闭按钮】<form><INPUT TYPE='BUTTON' value='关闭' onClick='window.close()'></form>呵呵,现在更加完美了!【内包含的弹出窗口——一个页面两个窗口】上面的例子都包含两个窗口,一个是主窗口,另一个是弹出的小窗口。
通过下面的例子,你可以在一个页面内完成上面的效果。
<html><head><SCRIPT LANGUAGE="javascript">function openwin(){OpenWindow=window.open("","newwin","height=250,width=250,toolbar=no,scrollbars="+ scroll+",menubar=no";);//写成一行OpenWindow.document.write("<TITLE>例子</TITLE>" ;)OpenWindow.document.write("<BODY BGCOLOR=#FFFFFF>" ;)OpenWindow.document.write("<H1>Hello!</h1>" ;)OpenWindow.document.write("New window opened!" ;)OpenWindow.document.write("</BODY >" ;)OpenWindow.document.write("</HTML>" ;)OpenWindow.document.close()}</script></head><body><a href="#" onclick="openwin()">打开一个窗口</a><input type="button" onclick="openwin()" value="/打开窗口"></body></html>看看OpenWindow.document.write()里面的代码不就是标准的HTML吗?只要按照格式写更多的行即可。
千万注意多一个标签或少一个标签都会出现错误。
记住用OpenWindow.document.close()结束啊。
【终极应用——弹出窗口的Cookie控制】回想一下,上面的弹出窗口虽然酷,但是有一点小毛病(你沉浸在喜悦之中,一定没有发现吧?)比如你将上面的脚本放在一个需要频繁经过的页面里(例如首页),那么每次刷新这个页面,窗口都会弹出一次,是不是非常烦人?有解决的办法吗?Yes!Follow me。
我们使用Cookie来控制一下就可以了。
首先,将如下代码加入主页面HTML的<HEAD>区:<script>function openwin(){window.open("page.html","","width=200,height=200" ;)}function get_cookie(Name){var search = Name+ "="var returnvalue ="";if (documents.cookie.length >0){offset = documents.cookie.indexOf(search)if (offset!=-1){offset += search.lengthend = documents.cookie.indexOf (";",offset);if (end ==-1)end = documents.cookie.length;returnvalue =unescape(documents.cookie.substring(offset,end))}}return returnvalue;}function loadpopup(){if (get_cookie('popped')==";){openwin()documents.cookie="popped=yes"}}</script>然后,用<body onload="loadpopup()">(注意不是openwin 而是loadpop啊)替换主页面中原有的<BODY>这一句即可。