标签:asp.net
1, 最基本的弹出窗口代码
  <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>
<%@ 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>
标签:asp.net
原文地址:http://blog.csdn.net/yayun0516/article/details/42098925