This article mainly introduces the code collection of JS pop-up windows, which has certain reference value. Now I share it with everyone. Friends in need can refer to
How to use web pages to pop up various forms of windows. I think most of you know a little bit about how to create various pop-up windows. I usually use my spare time to sort out some. Friends in need can refer to
How to use web page pop-ups I think most of you are aware of various forms of windows, but how to create various pop-up windows? Let’s learn today:
1. Pop up one Full screen window
Copy code The code is as follows:
<html> <body http://www.jb51.net','脚本之家','fullscreen');">; <b>www.jb51.net</b> </body> </html>
2. Pop up a window that has been F11ized
Copy code The code is as follows:
<html> <body 'http://www.jb51.net','脚本之家','channelmode');">; <b>www.jb51.net</b> </body> </html>
3. Pop up a window with a favorite link toolbar
Copy code The code is as follows:
<html> <body www.wangye8.com','脚本之家','width=400,height=300,directories');"> <b>www.wangye8.com</b> </body> </html>
4.Web page dialog box
Copy code The code is as follows:
<html> <SCRIPT LANGUAGE="javascript"> <!-- showModalDialog('http://www.jb51.net,'脚本之家','dialogWidth:400px;dialogHeight:300px; dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes') //--> </SCRIPT> <b>www.wangye8.com</b> </body> </html> <html> <SCRIPT LANGUAGE="javascript"> <!-- showModelessDialog('http://www.jb51.net,'脚本之家','dialogWidth:400px;dialogHeight:300px; dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes') //--> </SCRIPT> <b>http://www.wangye8.com</b> </body> </html>
showModalDialog() or showModelessDialog() to call the web dialog box. The difference between showModalDialog() and showModelessDialog() is that the window opened by showModalDialog() (modal window for short) is placed in The parent window must be closed to access the parent window (it is recommended to use it as little as possible to avoid offending); showModelessDialog()
dialogHeight: iHeight sets the height of the dialog window.
dialogWidth: iWidth sets the width of the dialog window.
dialogLeft: iXPos sets the left position of the dialog window relative to the upper left corner of the desktop.
dialogTop: iYPos sets the top position of the dialog window relative to the upper left corner of the desktop.
center: {yes | no | 1 | 0 } Specifies whether to center the dialog box on the desktop. The default value is "yes".
help: {yes | no | 1 | 0 } Specifies whether to display context-sensitive help icons in the dialog window. The default value is "yes".
resizable: {yes | no | 1 | 0 } Specifies whether the dialog window is resizable. The default value is "no".
status: {yes | no | 1 | 0 } Specifies whether the status bar is displayed in the dialog window. The default value is "yes" for modeless dialog windows and "no" for modal dialog windows.
5. Other pop-up window codes
Friends who often surf the Internet may have been to some websites. As soon as you enter the homepage, a window will pop up, or a link or button will pop up. Usually In this window, some notes, copyright information, warnings, welcome, etc. or information that the author wants to give special reminders will be displayed. In fact, it is very easy to create such a page. You only need to add a few pieces of javascript code to the HTML of the page. Below I will take you to analyze its mystery.
[The most basic pop-up window code]
In fact, the code is very simple:
##Copy code The code is as follows:
<SCRIPT LANGUAGE="java script"> <!-- window.open ('page.html') --> </SCRIPT>
Window.open ('page.html') is used to control the pop-up of a new window page.html. If page.html is not in the same path as the main window, the path should be stated in front, the absolute path (http:// ) and relative paths (../) are available.
You can use either single quotes or double quotes, just don't mix them.
This piece of code can be added to any position in the HTML, or between
Copy code The code is as follows:
<SCRIPT LANGUAGE="java script:> <!-- 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>
参数解释:
js脚本结束。
【用函数控制弹出窗口】
下面是一个完整的代码。
复制代码 代码如下:
<html> <head> <script LANGUAGE="java script"> <!-- 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 > ...任意的页面内容... </body> </html>
这里定义了一个函数openwin(),函数内容就是打开一个窗口。在调用它之前没有任何用途。怎么调用呢?
方法一:
复制代码 代码如下:
<script language="java script"> <!-- function openwin(){ window.open("page.html","","width=200,height=200" ;) } //--> </script>
加入
区:open即可。复制代码 代码如下:
<script language="java script"> function closeit() { setTimeout("self.close()",10000) //毫秒 } </script>
然后,再用
这一句话代替page.html中原有的这一句就可以了。(这一句话千万不要忘记写啊!这一句的作用是调用关闭窗口的代码,10秒钟后就自行关闭该窗口。)复制代码 代码如下:
<form> <INPUT TYPE='BUTTON' value='关闭' </form>
呵呵,现在更加完美了!
【内包含的弹出窗口——一个页面两个窗口】
上面的例子都包含两个窗口,一个是主窗口,另一个是弹出的小窗口。
通过下面的例子,你可以在一个页面内完成上面的效果。
复制代码 代码如下:
<html> <head> <SCRIPT LANGUAGE="java script"> 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="#" >打开一个窗口</a> <input type="button" value="打开窗口"> </body> </html>
看看OpenWindow.document.write()里面的代码不就是标准的HTML吗?只要按照格式写更多的行即可。千万注意多一个标签或少一个标签都会出现错误。记住用OpenWindow.document.close()结束啊。
【终极应用——弹出窗口的Cookie控制】
回想一下,上面的弹出窗口虽然酷,但是有一点小毛病(你沉浸在喜悦之中,一定没有发现吧?)比如你将上面的脚本放在一个需要频繁经过的页面里(例如首页),那么每次刷新这个页面,窗口都会弹出一次,是不是非常烦人?有解决的办法吗?Yes!Follow me。我们使用Cookie来控制一下就可以了。
首先,将如下代码加入主页面HTML的
复制代码 代码如下:
<script> function openpopup(){ window.open("hello.htm","","width=300,height=300") //自己修改弹出窗口 } function get_cookie(Name) { var search = Name + "=" var returnvalue = ""; if (documents.cookie.length > 0) { offset = documents.cookie.indexOf(search) if (offset != -1) { // if cookie exists offset += search.length // set index of beginning of value end = documents.cookie.indexOf(";", offset); // set index of end of cookie value if (end == -1) end = documents.cookie.length; returnvalue=unescape(documents.cookie.substring(offset, end)) } } return returnvalue; } function loadpopup(){ if (get_cookie('popped')==''){ openpopup() documents.cookie="popped=yes" } } </script> </head>
将如下代码键入BODY区:
复制代码 代码如下:
<script language="java script"> <!-- var gt = unescape('%3e'); var popup = null; var over = "Launch Pop-up Navigator"; popup = window.open('', 'popupnav', 'width=500,height=500,resizable=0,scrollbars=auto'); // width=500,height=500为窗口长和宽 if (popup != null) { if (popup.opener == null) { popup.opener = self; } popup.location.href = '要打开的文件名'; } // --> </script>
方法二:Cookies应用:控制弹出窗口 当我们在一个页面中设置一个POP弹出窗口后,每次只要重新浏览该页面,POP窗口就会自动弹出来,造成不必要的麻烦。那么怎么解决这个问题呢? 我在这里用一个简单的例子讲解一下如何通过操作Cookies让弹出窗口只在第一次浏览该页面时弹出,以后就不再招人烦了!
<script> function openpopwindow() { window.open("hello.htm","","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) { // 如果以前有cookies记录 offset += search.length; // 设置cookie的起始位置 end = documents.cookie.indexOf(";", offset); // 设置cookie的结束位置 if (end == -1) end = documents.cookie.length; returnvalue=unescape(documents.cookie.substring(offset, end)) } } return returnvalue; } function loadpopup() { if (get_cookie('popped')=='') { openpopwindow(); documents.cookie="popped=yes"; } } </script>
将上面的代码键入BODY区:
复制代码 代码如下:
<script LANGUAGE="javascript"> <!--Begin function leave(){ window.open ('1.htm',",'toolbar=no,menubar=no,location=no,height=225,width=235'); break } //END--> </script>
如何利用网页弹出各种形式的窗口,我想大家大多都是知道些的,但那种多种多样的弹出式窗口是怎么搞出来的,我们今天就来学习一下:
1.弹启一个全屏窗口
复制代码 代码如下:
<html> <body http://www.jb51.net','脚本之家','fullscreen');">; <b>www.jb51.net</b> </body> </html>
2.弹启一个被F11化后的窗口
复制代码 代码如下:
<html> <body 'http://www.jb51.net','脚本之家','channelmode');">; <b>www.jb51.net</b> </body> </html>
3.弹启一个带有收藏链接工具栏的窗口
复制代码 代码如下:
<html> <body www.wangye8.com','脚本之家','width=400,height=300,directories');"> <b>www.wangye8.com</b> </body> </html>
4.网页对话框
复制代码 代码如下:
<html> <SCRIPT LANGUAGE="javascript"> <!-- showModalDialog('http://www.jb51.net,'脚本之家','dialogWidth:400px;dialogHeight:300px; dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes') //--> </SCRIPT> <b>www.wangye8.com</b> </body> </html> <html> <SCRIPT LANGUAGE="javascript"> <!-- showModelessDialog('http://www.jb51.net,'脚本之家','dialogWidth:400px;dialogHeight:300px; dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes') //--> </SCRIPT> <b>http://www.wangye8.com</b> </body> </html>
showModalDialog()或是showModelessDialog() 来调用网页对话框,至于showModalDialog()与showModelessDialog()的区别,在于showModalDialog()打开的窗口(简称模式窗口),置在父窗口上,必须关闭才能访问父窗口(建议尽量少用,以免招人反感);showModelessDialog()
dialogHeight: iHeight 设置对话框窗口的高度。
dialogWidth: iWidth 设置对话框窗口的宽度。
dialogLeft: iXPos 设置对话框窗口相对于桌面左上角的left位置。
dialogTop: iYPos 设置对话框窗口相对于桌面左上角的top位置。
center: {yes | no | 1 | 0 } 指定是否将对话框在桌面上居中,默认值是“yes”。
help: {yes | no | 1 | 0 } 指定对话框窗口中是否显示上下文敏感的帮助图标。默认值是“yes”。
resizable: {yes | no | 1 | 0 } 指定是否对话框窗口大小可变。默认值是“no”。
status: {yes | no | 1 | 0 } 指定对话框窗口是否显示状态栏。对于非模式对话框窗口,默认值是“yes”;对于模式对话框窗口,默认值是 “no”。
5、其他弹出窗口代码
经常上网的朋友可能到过这样一些网站,一进入首页立刻会弹出一个窗口,或者按一个链接或按钮弹出,通常在这个窗口里会显示一些注意事项、版权信息、警告、欢迎光顾之类的话或者作者想要特别提示的信息。其实制作这样的页面非常容易,只要往该页面的HTML里加入几段java script代码即可实现。下面我就带你剖析它的奥秘。
【最基本的弹出窗口代码】
其实代码非常简单:
复制代码 代码如下:
<SCRIPT LANGUAGE="java script"> <!-- window.open ('page.html') --> </SCRIPT>
因为这是一段java script代码,所以它们应该放在之间。是对一些版本低的浏览器起作用,在这些老浏览器中如果不支持java script,不会将标签中的代码作为文本显示出来。
Window.open ('page.html')用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(../)均可。
用单引号和双引号都可以,只是不要混用。
这一段代码可以加入HTML的任意位置,加入到
复制代码 代码如下:
<SCRIPT LANGUAGE="java script:> <!-- 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>
参数解释:
js脚本结束。
【用函数控制弹出窗口】
下面是一个完整的代码。
复制代码 代码如下:
<html> <head> <script LANGUAGE="java script"> <!-- 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 > ...任意的页面内容... </body> </html>
这里定义了一个函数openwin(),函数内容就是打开一个窗口。在调用它之前没有任何用途。怎么调用呢?
方法一:
复制代码 代码如下:
<script language="java script"> <!-- function openwin(){ window.open("page.html","","width=200,height=200" ;) } //--> </script>
加入
区:open即可。复制代码 代码如下:
<script language="java script"> function closeit() { setTimeout("self.close()",10000) //毫秒 } </script>
然后,再用
这一句话代替page.html中原有的这一句就可以了。(这一句话千万不要忘记写啊!这一句的作用是调用关闭窗口的代码,10秒钟后就自行关闭该窗口。)复制代码 代码如下:
<form> <INPUT TYPE='BUTTON' value='关闭' </form>
呵呵,现在更加完美了!
【内包含的弹出窗口——一个页面两个窗口】
上面的例子都包含两个窗口,一个是主窗口,另一个是弹出的小窗口。
通过下面的例子,你可以在一个页面内完成上面的效果。
复制代码 代码如下:
<html> <head> <SCRIPT LANGUAGE="java script"> 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="#" >打开一个窗口</a> <input type="button" value="打开窗口"> </body> </html>
看看OpenWindow.document.write()里面的代码不就是标准的HTML吗?只要按照格式写更多的行即可。千万注意多一个标签或少一个标签都会出现错误。记住用OpenWindow.document.close()结束啊。
相关推荐:
js implementation code to close the window function of the js pop-up layer
The above is the detailed content of JS pop-up window code collection. For more information, please follow other related articles on the PHP Chinese website!