弹出窗口代码(弹出窗口代码怎么关闭)

大家好,今天来为大家分享弹出窗口代码的一些知识点,和弹出窗口代码怎么关闭的问题解析,大家要是都明白,那么可以忽略,如果不太清楚的话可以看看本篇文章,相信很大概率可以解决您的问题,接下来我们就一起来看看吧!

在网页设计中,弹出窗口是一个非常重要的元素。它能够帮助我们更好地引导用户、展示重要信息,甚至实现一些有趣的交互效果。如何制作一个美观、实用的弹出窗口呢?今天,就让我带你一起走进弹出窗口的代码世界,从入门到精通!

一、了解弹出窗口

1. 弹出窗口的定义

弹出窗口,顾名思义,就是指在用户浏览网页时,突然出现在屏幕上的一个新窗口。它可以是模态的,也可以是非模态的。模态弹出窗口会阻止用户与主窗口的交互,而非模态弹出窗口则不会。

2. 弹出窗口的应用场景

* 引导用户注册/登录

* 展示重要信息

* 实现表单提交

* 弹出广告

二、弹出窗口的HTML结构

我们需要构建一个基本的弹出窗口HTML结构。以下是一个简单的例子:

“`html

1、最基本的弹出窗口代码

< SCRIPT LANGUAGE=”javascript”>

<!–

window.open(“page.html”)

–>

</SCRIPT>

window.open(“page.html”)用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(../)均可。

2、经过设置后的弹出窗口

< 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”)&nbsp;

->

</SCRIPT>

< SCRIPT LANGUAGE=”javascript”> js脚本开始;window.open弹出新窗口的命令;”page.html”弹出窗口的文件名;”newwindow”弹出窗口的名字(不是文件名),非必须,可用空”代替;

3、用函数控制弹出窗口

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

这里定义了一个函数openwin(),函数内容就是打开一个窗口。

4、同时弹出2个窗口

< script LANGUAGE=”JavaScript”>

<!–

function openwin(){

window.open(“page.html”,”newwindow”,”height=100, width=100, top=0, left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no”)

&nbsp;

window.open(“page2.html”,”newwindow2″,”height=100, width=100, top=100, left=100,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no”)

}

–>

</script>

为避免弹出的2个窗口覆盖,用top和left控制一下弹出的位置不要相互覆盖即可。

5、主窗口打开文件1.htm,同时弹出小窗口page.html

< script language=”javascript”>

<!–

function openwin(){

window.open(“page.html”,””,”width=200,height=200″)

}

–>

</script>

关于dreamweaver中插入弹出广告窗口的代码

这个效果要用JS实现.单纯的DW还是不行,需要懂一些JS知识.下面的代码可以实现这个效果,你可以复制代码保存为htm格式看看效果.

<body scroll=no>

<script language=”JavaScript”>

window.onload= getMsg;

window.onresize= resizeDiv;

window.onerror= function(){}

//短信提示使用(asilas添加)

var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,objTimer,i= 0;

function getMsg()

{

try{

divTop= parseInt(document.getElementById(“eMeng”).style.top,10)

divLeft= parseInt(document.getElementById(“eMeng”).style.left,10)

divHeight= parseInt(document.getElementById(“eMeng”).offsetHeight,10)

divWidth= parseInt(document.getElementById(“eMeng”).offsetWidth,10)

docWidth= document.body.clientWidth;

docHeight= document.body.clientHeight;

document.getElementById(“eMeng”).style.top= parseInt(document.body.scrollTop,10)+ docHeight+ 10;// divHeight

document.getElementById(“eMeng”).style.left= parseInt(document.body.scrollLeft,10)+ docWidth- divWidth

document.getElementById(“eMeng”).style.visibility=”visible”

objTimer= window.setInterval(“moveDiv()”,10)

}

catch(e){}

}

function resizeDiv()

{

i+=1

if(i>5000) closeDiv()//修改这个数字以改变窗口存活期,越大存活期越长。

try{

divHeight= parseInt(document.getElementById(“eMeng”).offsetHeight,10)

divWidth= parseInt(document.getElementById(“eMeng”).offsetWidth,10)

docWidth= document.body.clientWidth;

docHeight= document.body.clientHeight;

document.getElementById(“eMeng”).style.top= docHeight- divHeight+ parseInt(document.body.scrollTop,10)

document.getElementById(“eMeng”).style.left= docWidth- divWidth+ parseInt(document.body.scrollLeft,10)

}

catch(e){}

}

function moveDiv()

{

try

{

if(parseInt(document.getElementById(“eMeng”).style.top,10)<=(docHeight- divHeight+ parseInt(document.body.scrollTop,10)))

{

window.clearInterval(objTimer)

objTimer= window.setInterval(“resizeDiv()”,1)

}

divTop= parseInt(document.getElementById(“eMeng”).style.top,10)

document.getElementById(“eMeng”).style.top= divTop- 1

}

catch(e){}

}

function closeDiv()

{

document.getElementById('eMeng').style.visibility='hidden';

if(objTimer) window.clearInterval(objTimer)

}

</script>

<DIV id=eMeng style=”BORDER-RIGHT:#455690 1px solid; BORDER-TOP:#a6b4cf 1px solid; Z-INDEX:99999; LEFT: 0px; VISIBILITY: hidden; BORDER-LEFT:#a6b4cf 1px solid; WIDTH: 180px; BORDER-BOTTOM:#455690 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: 116px; BACKGROUND-COLOR:#c9d3f3″>

<TABLE style=”BORDER-TOP:#ffffff 1px solid; BORDER-LEFT:#ffffff 1px solid” cellSpacing=0 cellPadding=0 width=”100%” bgColor=#cfdef4 border=0>

<TBODY>

<TR>

<TD width=161 height=24 style=”FONT-SIZE: 12px; BACKGROUND-IMAGE: url(msgTopBg.gif); COLOR:#0f2c8c;padding-left:10px”>*****网视频</TD>

<TD style=”BACKGROUND-IMAGE: url(msgTopBg.gif); PADDING-TOP: 2px;PADDING-right:2px” vAlign=center align=right width=19><span title=关闭 style=”CURSOR: hand;color:red;font-size:12px;font-weight:bold;margin-right:4px;” onclick=closeDiv()>×</span><!–<IMG title=关闭 style=”CURSOR: hand” onclick=closeDiv() hspace=3 src=”msgClose.jpg”>–></TD>

</TR>

<TR>

<TD style=”PADDING-RIGHT: 1px; BACKGROUND-IMAGE: url(1msgBottomBg.jpg); PADDING-BOTTOM: 1px” colSpan=2 height=90>

<!—在SRC=””里面修改加入你的视频地址,或者你可以换更好的视频播放器–>

<embed src='mms://61.175.132.221/tv/mtv/f4/makeawish.wmv' width=200 height=150 autostart=true loop=true></embed></TD>

</TR>

</TBODY>

</TABLE>

</DIV>

</body>

html 弹出窗口有几种方式

介绍几种方法:

第一种:javascripts代码

<SCRIPTLANGUAGE=”javascript”>

<!–

window.open('page.html')

–>

</SCRIPT>

这一段代码可以加入HTML的任意位置,<head>和</head>之间可以,<body>间</body>也可以,越前越早执行,尤其是页面代码长,又想使页面早点弹出就尽量往前放。也可以,越前越早执行,尤其是页面代码长,又想使页面早点弹出就尽量往前放。

第二种:

<SCRIPTLANGUAGE=”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>

第三种:函数控制

下面是一个完整的代码:

<html>

<head>

<scriptLANGUAGE=”javascript”>

<!–

functionopenwin(){

window.open(“page.html”,”newwindow”,”height=100,width=400,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no”)

//写成一行

}

//–>

</script>

</head>

<bodyonload=”openwin()”>

…任意的页面内容…

</body>

</html>

上面这三种弹出窗口的代码都可以应用。

文章分享结束,弹出窗口代码和弹出窗口代码怎么关闭的答案你都知道了吗?欢迎再次光临本站哦!

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享