1, 最主要的弹出窗体代码

   window.open('page.html');



2, 经过设置后的弹出窗体

   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')   //该句写成一行代码

   參数解释:

      window.open 弹出新窗体的命令; 

  'page.html' 弹出窗体的文件名称; 

  'newwindow' 弹出窗体的名字(不是文件名称)。非必须,可用空''取代; 

  height=100 窗体高度。 

  width=400 窗体宽度; 

  top=0 窗体距离屏幕上方的象素值。 

  left=0 窗体距离屏幕左側的象素值。 

  toolbar=no 是否显示工具栏,yes为显示; 

  menubar。scrollbars 表示菜单条和滚动条。 

  resizable=no 是否同意改变窗体大小,yes为同意; 

  location=no 是否显示地址栏。yes为同意; 

  status=no 是否显示状态栏内的信息(一般是文件已经打开),yes为同意。



3, 用函数控制弹出窗体

    以下是一段完整的代码

      <html> 

  <head> 

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

  </head> 

  <body onload="openwin()"> 

  随意的页面内容... 

  </body> 

  </html> 

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

在调用它之前没有不论什么用途。怎么调用呢?

   

   方法一:<body onload="openwin()"> 浏览器读页面时弹出窗体;

   方法二:<body onunload="openwin()"> 浏览器离开页面时弹出窗体;

   方法三:用一个连接调用:

              <a href="#" onclick="openwin()"> 打开一个窗体</a>

              注意:使用的"#"是虚连接。

   方法四:用一个按扭调用:

               <input type="button" onclick="openwin()" value="打开窗体" />



4, 弹出两个窗体

    对代码略微修改例如以下:

    <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=n
o, status=no")//写成一行 

  window.open ("page2.html", "newwindow2", "height=100, width=100, top=100, left=100,toolbar=no, menubar=no, scrollbars=no, resizable=no, loca
tion=no, status=no")//写成一行 

  } 

  //--> 

  </script>

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

最后用上面的说过的四种方法调用就可以。

      注意:2个窗体的name(newwindow与 newwindow2)不要同样,或者干脆所有为空。



5, 主窗体打开文件1.htm,同一时候弹出小窗体page.html

    例如以下代码增加主窗体<head>区:

    function openwin()

    {

     window.open("page.html","","width=200,height=200") 

    }

    增加body区:

    <a href="1.htm" onclick="openwin()">open</a>就可以。



6, 弹出的窗体之定时关闭控制

    将一小段代码增加弹出的页面(注意是增加page.html的HTML中。可不是主页面中。否则......),让它在10秒后自己主动关闭是不是更酷了?

    function closeit()

    {

    setTimeout("selft.close()", 10000)   //毫秒

    }

    然后。在body 中加入:<body onload="closeit()">就可以。



7, 在弹出窗体中加上一个关闭按扭

    <input type="button" value="关闭" onclick="window.close()">



8, 内包括的弹出窗体---一个页面两个窗体

    上面的样例都包括两个窗体。一个是主窗体。还有一个是弹出的小窗体。通过以下的样例。你能够在一个页面内完毕上面的效果。

  <html> 

  <head> 

  <SCRIPT LANGUAGE="JavaScript"> 

  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="#" onclick="openwin()">打开一个窗体</a> 

  <input type="button" onclick="openwin()" value="打开窗体"> 

  </body> 

  </html> 

      OpenWindow.document.write()里面的代码不就是标准的HTML吗?仅仅要依照 格式写很多其它的行就可以。

千万注意多一个标签或少一个标签就会出现错误。记得用 OpenWindow.document.close()结束啊。 



9, 终极应用---弹出的窗体这Cookie控制

    回忆一下,上面的弹出窗体尽管酷,可是有一点小毛病。比方你将上面的脚本放在一个须要频繁经过的页面里(比如首页)。那么每次刷新这个页面,窗体都会弹出一次,是不是很烦人?

    有解决的办法吗?我们使用cookie来控制就可以。

首先。将例如以下代码增加主页面的Html的head区:

    function openwin(){ 

  window.open("page.html","","width=200,height=200") 

  } 

      function get_cookie(Name)

      {

       var search=Name+"=";

       var returnvalue="";

       if(document.cookie.length>0){

      if (offset != -1) { 

      offset += search.length 

      end = document.cookie.indexOf(";", offset); 

      if (end == -1) 

      end = document.cookie.length; 

      returnvalue=unescape(document.cookie.substring(offset, end));

      }

      }

      return returnvalue;

      }

      function ladpopup()

      {

      if(get_cookie('popped=yes'))

      {

      openwin()

      document.cookie="popped=yes";

      }

      }

     最后,用<body onload="loadpopup()">

父级.aspx代码例如以下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="弹出窗体.aspx.cs" Inherits="弹出窗体" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title> </head>
<body onbeforeunload="return confirm('确定要离开吗?')">
<form id="form1" runat="server">
<div> <input id="Button1" type="button" value="button" onclick="window.open('ChildWin.aspx','弹出框','width=900,height=450,top=300,left=300');"/></div>
</form>
</body>
</html>

ChildWin.aspx代码例如以下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ChildWin.aspx.cs" Inherits="ChildWin" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div> <asp:BulletedList ID="BulletedList1" runat="server" Width="526px">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
</asp:BulletedList> <br />
<input id="Button1" type="button" value="关闭" OnClick="window.close();"/></div>
</form>
</body>
</html>

最新文章

  1. 机器学习笔记-----AP(affinity propagat)算法讲解及matlab实现
  2. js的url解析函数封装
  3. Excel 同时打开2个或多个独立窗口
  4. 图解,为多个oracle数据库下添加ArcSde实例
  5. redhat enterprixe 5.0 DNS 服务配置与管理
  6. hdu 4571 floyd+动态规划
  7. SQL Server 收缩事务日志的方法
  8. Base-Android快速开发框架(四)--网络操作之FastJson以及AsyncHttpClient
  9. Python标准库之urllib,urllib2
  10. poj 3422 (费用流)
  11. 淘宝对接API
  12. javascript每日一练(四)——DOM二
  13. HDU4549 M斐波那契数
  14. scrapy bug
  15. centos 把网卡名称修改为 eth0
  16. springboot集成swagger
  17. JavaScript 计算指定月份有多少天
  18. Integer判断大于 == 127时的坑
  19. 非关系型数据库mongodb的语法模式
  20. iOS动画学习

热门文章

  1. [转]Window2008站点安全设置,IIS7/IIS7.5中目录执行权限的设置方法
  2. 微信小程序 &quot;request:fail 发生了 SSL 错误无法建立与该服务器的安全连接。&quot;
  3. java攻城狮之路--复习JDBC(数据库连接池 : C3P0、DBCP)
  4. [Windows Server 2008] 安装SQL SERVER 2008
  5. oracle 入门笔记--v$sql和v$sqlarea视图(转载)
  6. windows远程桌面连接
  7. ArcEngine生成矩形缓冲区
  8. cshtml中字符串中表示特殊字符@
  9. 环形缓冲区: ringbuf.c
  10. 【vue】vue中实现标签页