HTML弹出窗口

时间:2023-03-08 22:32:35
HTML弹出窗口

1.最简单的

<script type="text/javascript">
<!--
window.open("http://cn.bing.com");
window.open("../../page.html");
window.open("some.html");
window.open("some.html","some_tag","height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no");
-->
</script>

2.使用函数

<script type="text/javascript">
function open_window(){
window.open("some.html");
}
</script>

调用:

1.<body onload="open_window()">    //打开网页弹出
2.<body onunload="open_window()"> //关闭网页弹出
3.<a href="#" onclick="open_window()"> //点击链接弹出

3.让弹出的窗口自动关闭

<script type="text/javascript>
function close_itself(){
setTimeout("self.close()", 10000); //10秒后关闭
}
</script>

4.在当前窗口内弹出

<script type="text/javascript">
OpenWindow=window.open("", "some_tag", "height=250,width=250,toolbar=no,scrollbars="+scroll+",menubar=no");
OpenWindow.document.write("<TITLE>some_example</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>

5.弹出窗口之Cookie控制

<script type="text/javascript">
function open_window(){
window.open("some.html","some_tag","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=(documents.cookie.substring(offset, end));
}
}
return returnvalue;
}
function loadpopup(){
  if (get_cookie('popped')==''){
    open_window();
    documents.cookie="popped=yes";
  }
}
</script>

6.弹出窗口渐变大

1. 居中弹出窗口, 并逐步扩大
<script type="text/javascript">
if (navigator.appName=="Microsoft Internet Explorer") {//最大化窗口
self.moveTo(-5,-5);
self.resizeTo(screen.availWidth +8,screen.availHeight+8) //这个脚本定义的宽度其实比原窗口还要大那么一点.
}
var w=h=200;
x=(screen.width-w)/2;
y=(screen.height-h)/2;
var n=open('','newWin','width='+w+',height='+h+',left='+x+',right='+x+',top='+y+',bottom='+y);
n.document.write('
<script>
document.write("temp"); /* 临时内容, 去掉出错 */
document.body.innerHTML=""; /* 清空页面内容 */
document.onclick=function() /* 单击关闭窗口 */
</script>');
n.document.write('<h2>test moving window</h2>');
n.focus();
var timer=setInterval('fMovingWin()',1);
function fMovingWin(){
if (n.closed||(w>=screen.width+8&&h>=screen.height+8)) {
clearInterval(timer);
return;
}
try{
if(w<=screen.width+8)w+=2;
if(h<=screen.height+8)h+=2;
n.resizeTo(w, h)
x=(screen.width-w)/2;
y=(screen.height-h)/2;
n.moveTo(x,y)
} catch(e) {} //shawl.qiu script
}
</script>

end