Home  >  Article  >  Web Front-end  >  JS pop-up window code collection

JS pop-up window code collection

不言
不言Original
2018-05-07 16:03:142182browse

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&#39;,&#39;脚本之家&#39;,&#39;fullscreen&#39;);">; 
<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 &#39;http://www.jb51.net&#39;,&#39;脚本之家&#39;,&#39;channelmode&#39;);">; 
<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&#39;,&#39;脚本之家&#39;,&#39;width=400,height=300,directories&#39;);"> 
<b>www.wangye8.com</b> 
</body> 
</html>

4.Web page dialog box

Copy code The code is as follows:

<html> 
<SCRIPT LANGUAGE="javascript"> 
<!-- 
showModalDialog(&#39;http://www.jb51.net,&#39;脚本之家&#39;,&#39;dialogWidth:400px;dialogHeight:300px; 
dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes&#39;) 
//--> 
</SCRIPT> 
<b>www.wangye8.com</b> 
</body> 
</html> 
<html> 
<SCRIPT LANGUAGE="javascript"> 
<!-- 
showModelessDialog(&#39;http://www.jb51.net,&#39;脚本之家&#39;,&#39;dialogWidth:400px;dialogHeight:300px; 
dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes&#39;) 
//--> 
</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 (&#39;page.html&#39;) 
--> 
</SCRIPT>

Because this is a piece of java script code, they should be placed between the a07abf01b6c752309165e3ab48f0ed0d tag and 2cacc6d41bbb37262a98f745aa00fbf0. 64319fc22de3df1e5972a1902b476065 are effective for some older browsers. If javascript is not supported in these old browsers, the code in the tag will not be displayed as text.

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 93f0f5c25f18dab9d176bd4f6de5d30e and 9c3bca370b5104690d9ef395f2c5f8d1. The earlier the position, the earlier it will be executed, especially when the page code is long and you want to make the page If it pops up early, put it as far forward as possible.

[Pop-up window after setting] Let’s talk about the settings of the appearance of the pop-up window. Just add a little more to the code above.
Let's customize the appearance, size, and pop-up position of this pop-up window to suit the specific conditions of the page.

Copy code The code is as follows:

<SCRIPT LANGUAGE="java script:> 
<!-- 
window.open (&#39;page.html&#39;,&#39;newwindow&#39;,&#39;height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no, 
location=no,status=no&#39;) 
//写成一行 
--> 
</SCRIPT>

参数解释
666a490946c7e637601a1894f6d86595 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为允许;
db271416853c42fd247a57c1a2c29eb6 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(),函数内容就是打开一个窗口。在调用它之前没有任何用途。怎么调用呢?
方法一:e1248121fb6027a542bf30520c4b8337 浏览器读页面时弹出窗口;
方法二:e1248121fb6027a542bf30520c4b8337 浏览器离开页面时弹出窗口;
方法三:用一个连接调用:34841a6383e353a57ec198322225afba打开一个窗口5db79b134e9f6b82c0b36e0489ee08ed
注意:使用的"#"是虚连接。
方法四:用一个按钮调用:cea394c8ee8e07e1a5afe8bd627f1de4

【主窗口打开文件1.htm,同时弹出小窗口page.html】
将如下代码加入主窗口93f0f5c25f18dab9d176bd4f6de5d30e区:

复制代码 代码如下:

<script language="java script"> 
<!-- 
function openwin(){ 
window.open("page.html","","width=200,height=200" ;) 
} 
//--> 
</script>

加入6c04bd5ca3fcae76e30b72ad730ca86d区:36004b2e0532268aed5a5320d4f0566copen5db79b134e9f6b82c0b36e0489ee08ed即可。

【弹出的窗口之定时关闭控制】
下面我们再对弹出窗口进行一些控制,效果就更好了。如果我们再将一小段代码加入弹出的页面(注意是加入到page.html的HTML中,可不是主页面中,否则…),让它在10秒钟后自动关闭是不是更酷了?
首先,将如下代码加入page.html文件的93f0f5c25f18dab9d176bd4f6de5d30e区:

复制代码 代码如下:

<script language="java script"> 
function closeit() { 
setTimeout("self.close()",10000) //毫秒 
} 
</script>

然后,再用e1248121fb6027a542bf30520c4b8337这一句话代替page.html中原有的a64997a0904a094b4570728d7f327acd这一句就可以了。(这一句话千万不要忘记写啊!这一句的作用是调用关闭窗口的代码,10秒钟后就自行关闭该窗口。)

【在弹出窗口中加上一个关闭按钮】

复制代码 代码如下:

<form> 
<INPUT TYPE=&#39;BUTTON&#39; value=&#39;关闭&#39; 
</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的ef1cac8df639bc9110cb13b8b5ab3dd7区:

复制代码 代码如下:

<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(&#39;popped&#39;)==&#39;&#39;){ 
openpopup() 
documents.cookie="popped=yes" 
} 
} 
</script> 
</head>

将如下代码键入BODY区:
e1248121fb6027a542bf30520c4b8337 //pop when leave page
或者:
e1248121fb6027a542bf30520c4b8337 //pop when enter page
你可以试着刷新一下这个页面或重新进入该页面,窗口再也不会弹出了。真正的Pop-Only-Once!
写到这里,弹出窗口的制作和应用技巧基本上算是讲完了,希望对正在制作网页的朋友有所帮助我就非常欣慰了。
需要注意的是,JS脚本中的大小写最好前后保持一致。
没有菜单、工具栏、地址栏的弹出窗口:

复制代码 代码如下:

<script language="java script"> 
<!-- 
var gt = unescape(&#39;%3e&#39;); 
var popup = null; 
var over = "Launch Pop-up Navigator"; 
popup = window.open(&#39;&#39;, &#39;popupnav&#39;, &#39;width=500,height=500,resizable=0,scrollbars=auto&#39;); // width=500,height=500为窗口长和宽 
if (popup != null) { 
if (popup.opener == null) { 
popup.opener = self; } 
popup.location.href = &#39;要打开的文件名&#39;; 
} 
// --> 
</script>

方法二:Cookies应用:控制弹出窗口 当我们在一个页面中设置一个POP弹出窗口后,每次只要重新浏览该页面,POP窗口就会自动弹出来,造成不必要的麻烦。那么怎么解决这个问题呢? 我在这里用一个简单的例子讲解一下如何通过操作Cookies让弹出窗口只在第一次浏览该页面时弹出,以后就不再招人烦了!
3f1c4e4b6b16bbbd69b2ee476dc4f83a 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"; } } 2cacc6d41bbb37262a98f745aa00fbf0
将上面的代码键入BODY区: e1248121fb6027a542bf30520c4b8337 //离开页面的时候弹出
或者: e1248121fb6027a542bf30520c4b8337 //打开页面的时候弹出

【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】
离开页面时弹开窗口效果:
效果:别人关闭这个页面的时候,弹出一个窗口,你可以写一些祝福的话
核心代码:

复制代码 代码如下:

<script LANGUAGE="javascript"> 
<!--Begin function leave(){ 
window.open 
(&#39;1.htm&#39;,",&#39;toolbar=no,menubar=no,location=no,height=225,width=235&#39;); 
break 
} 
//END--> 
</script>

如何利用网页弹出各种形式的窗口,我想大家大多都是知道些的,但那种多种多样的弹出式窗口是怎么搞出来的,我们今天就来学习一下:
1.弹启一个全屏窗口

复制代码 代码如下:

<html> 
<body http://www.jb51.net&#39;,&#39;脚本之家&#39;,&#39;fullscreen&#39;);">; 
<b>www.jb51.net</b> 
</body> 
</html>

2.弹启一个被F11化后的窗口

复制代码 代码如下:

<html> 
<body &#39;http://www.jb51.net&#39;,&#39;脚本之家&#39;,&#39;channelmode&#39;);">; 
<b>www.jb51.net</b> 
</body> 
</html>

3.弹启一个带有收藏链接工具栏的窗口

复制代码 代码如下:

<html> 
<body www.wangye8.com&#39;,&#39;脚本之家&#39;,&#39;width=400,height=300,directories&#39;);"> 
<b>www.wangye8.com</b> 
</body> 
</html>

4.网页对话框

复制代码 代码如下:

<html> 
<SCRIPT LANGUAGE="javascript"> 
<!-- 
showModalDialog(&#39;http://www.jb51.net,&#39;脚本之家&#39;,&#39;dialogWidth:400px;dialogHeight:300px; 
dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes&#39;) 
//--> 
</SCRIPT> 
<b>www.wangye8.com</b> 
</body> 
</html> 
<html> 
<SCRIPT LANGUAGE="javascript"> 
<!-- 
showModelessDialog(&#39;http://www.jb51.net,&#39;脚本之家&#39;,&#39;dialogWidth:400px;dialogHeight:300px; 
dialogLeft:200px;dialogTop:150px;center:yes;help:yes;resizable:yes;status:yes&#39;) 
//--> 
</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 (&#39;page.html&#39;) 
--> 
</SCRIPT>

因为这是一段java script代码,所以它们应该放在bea6dc94a5198d867c119ba7bd92f699标签和2cacc6d41bbb37262a98f745aa00fbf0之间。f69bf4a9fcda7e39ab7680cbdd8ba73f是对一些版本低的浏览器起作用,在这些老浏览器中如果不支持java script,不会将标签中的代码作为文本显示出来。
Window.open ('page.html')用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(../)均可。
用单引号和双引号都可以,只是不要混用。
这一段代码可以加入HTML的任意位置,加入到93f0f5c25f18dab9d176bd4f6de5d30e和9c3bca370b5104690d9ef395f2c5f8d1之间也可以,位置越靠前执行越早,尤其是页面代码较长时,又想使页面早点弹出就尽量往前放。
【经过设置后的弹出窗口】
下面再说一说弹出窗口外观的设置。只要再往上面的代码中加一点东西就可以了。
我们来定制这个弹出窗口的外观、尺寸大小、弹出位置以适应该页面的具体情况。

复制代码 代码如下:

<SCRIPT LANGUAGE="java script:> 
<!-- 
window.open (&#39;page.html&#39;,&#39;newwindow&#39;,&#39;height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no, 
location=no,status=no&#39;) 
//写成一行 
--> 
</SCRIPT>

参数解释:
666a490946c7e637601a1894f6d86595 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为允许;
db271416853c42fd247a57c1a2c29eb6 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(),函数内容就是打开一个窗口。在调用它之前没有任何用途。怎么调用呢?
方法一:e1248121fb6027a542bf30520c4b8337 浏览器读页面时弹出窗口;
方法二:e1248121fb6027a542bf30520c4b8337 浏览器离开页面时弹出窗口;
方法三:用一个连接调用:34841a6383e353a57ec198322225afba打开一个窗口5db79b134e9f6b82c0b36e0489ee08ed
注意:使用的"#"是虚连接。
方法四:用一个按钮调用:cea394c8ee8e07e1a5afe8bd627f1de4

【主窗口打开文件1.htm,同时弹出小窗口page.html】
将如下代码加入主窗口93f0f5c25f18dab9d176bd4f6de5d30e区:

复制代码 代码如下:

<script language="java script"> 
<!-- 
function openwin(){ 
window.open("page.html","","width=200,height=200" ;) 
} 
//--> 
</script>

加入6c04bd5ca3fcae76e30b72ad730ca86d区:36004b2e0532268aed5a5320d4f0566copen5db79b134e9f6b82c0b36e0489ee08ed即可。

【弹出的窗口之定时关闭控制】
下面我们再对弹出窗口进行一些控制,效果就更好了。如果我们再将一小段代码加入弹出的页面(注意是加入到page.html的HTML中,可不是主页面中,否则…),让它在10秒钟后自动关闭是不是更酷了?
首先,将如下代码加入page.html文件的93f0f5c25f18dab9d176bd4f6de5d30e区:

复制代码 代码如下:

<script language="java script"> 
function closeit() { 
setTimeout("self.close()",10000) //毫秒 
} 
</script>

然后,再用e1248121fb6027a542bf30520c4b8337这一句话代替page.html中原有的a64997a0904a094b4570728d7f327acd这一句就可以了。(这一句话千万不要忘记写啊!这一句的作用是调用关闭窗口的代码,10秒钟后就自行关闭该窗口。)

【在弹出窗口中加上一个关闭按钮】

复制代码 代码如下:

<form> 
<INPUT TYPE=&#39;BUTTON&#39; value=&#39;关闭&#39; 
</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 pop-up window JS pop-up DIV and darken the background of the entire page function implementation code

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn