1、弹出窗口的参数设置
<SCRIPT LANGUAGE="javascript">
<!--
window.open ('popuppage.html', 'windowsname', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no,status=no') //这句要写成一行
-->
</SCRIPT>
参数解释:
'popuppage.html' ------------弹出窗口的文件名;
'windowsname' --------------弹出窗口的名字(不是文件名),非必须,可用空''代替;
height=100 --------------------窗口高度;
width=400 ---------------------窗口宽度;
top=0 ---------------------------窗口距离屏幕上方的象素值;
left=0 ---------------------------窗口距离屏幕左侧的象素值;
toolbar=no --------------------是否显示工具栏,yes为显示;
menubar=no -----------------是否显示菜单栏,yes为显示;
scrollbars=no----------------是否显示滚动栏,yes为显示;
resizable=no -----------------是否允许改变窗口大小,yes为允许;
location=no ------------------是否显示地址栏,yes为允许;
status=no --------------------是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
2、弹出窗口的10秒后定时关闭。
将如下代码加入窗口的'popuppage.html'文件的<head>区:
<script language="javascript">
function closeit()
{
setTimeout("self.close()",10000) //1秒=1000毫秒
}
</script>
3、动态改变弹出窗口的内容
<SCRIPT LANGUAGE="javascript">
function openwin()
{
OpenWindow=window.open("", "windowsname", height=200, width=200);
OpenWindow.document.write("<HTML>")
OpenWindow.document.write("<BODY>")
OpenWindow.document.write("<h1>Hello!</h1>")
OpenWindow.document.write("</BODY>")
OpenWindow.document.write("</HTML>")
OpenWindow.document.close()
}
</SCRIPT>
4、弹出窗口用Cookie控制只显示一次。
将如下代码加入调用弹出窗口的<HEAD>区:
<script>
function openwin(){
window.open("popuppage.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.length
end = 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 οnlοad="loadpopup()">调用。
5、弹出窗口的关闭
<script>
window.close()
</script>