HTML(递归调用关闭)
 1 <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="CsvExport.WebForm1" %>
 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
 3 <HTML>
 4     <HEAD>
 5         <title>WebForm1</title>
 6         <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
 7         <meta content="C#" name="CODE_LANGUAGE">
 8         <meta content="JavaScript" name="vs_defaultClientScript">
 9         <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
10         <script type="text/javascript">
11         <!--
12             var $ = function(objId) {
13                 return document.getElementById(objId);
14             }
15             window.onload = function() {
16                 $('btn1').onclick = CsvOutPut1;
17                 $('btn2').onclick = CsvOutPut2;
18                 $('btn3').onclick = CsvOutPut3;
19             }
20         
21             function CsvOutPut1() {
22                 $('ifr1').setAttribute('src''Background.aspx?code=A');
23                 setTimeout("$('ifr2').setAttribute('src', 'Background.aspx?code=B')"100);
24             }
25             
26             //説明:IE7はOpenした画面を自動にCloseできること、しかしIE6の方は自動にCloseできないで、手動でClose必要。
27             var subWin = null;
28             function CsvOutPut2() {
29                 subWin = window.open('Background.aspx?code=A','','height=0,width=0,top=8000,left=8000');
30                 setTimeout("closeSubWin()"2000);
31                 setTimeout("document.getElementById('ifr2').setAttribute('src', 'Background.aspx?code=B')"100);
32             }
33             
34             function closeSubWin() {
35                 if (subWin != null && !subWin.closed) {
36                     subWin.close();
37                     setTimeout("closeSubWin()"1000);
38                 }
39                 return;
40             }
41             
42             function CsvOutPut3() {
43                 $('a1').click();
44                 $('a2').click();
45             }
46         //-->
47         </script>
48     </HEAD>
49     <body MS_POSITIONING="GridLayout">
50         <form id="Form1" method="post" runat="server">
51             <asp:Label id="Label2" style="Z-INDEX: 105; LEFT: 120px; POSITION: absolute; TOP: 64px" runat="server"
52                 Width="224px">IE6 IE7 OK</asp:Label>
53             <asp:Label id="Label3" style="Z-INDEX: 106; LEFT: 120px; POSITION: absolute; TOP: 104px" runat="server"
54                 Width="224px">IE7 OK</asp:Label><iframe id="ifr1" width="0" height="0"></iframe>
55             <iframe id="ifr2" width="0" height="0"></iframe><input id="btn1" style="Z-INDEX: 100; LEFT: 24px; POSITION: absolute; TOP: 16px" type="button"
56                 value="Button1"> <input id="btn2" style="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 56px" type="button"
57                 value="Button2"> <input id="btn3" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 96px" type="button"
58                 value="Button3"> <id="a1" href="Background.aspx?code=A" target="_blank"></A>
59             <asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 120px; POSITION: absolute; TOP: 24px" runat="server"
60                 Width="224px">IE7 OK</asp:Label><id="a2" href="Background.aspx?code=B"></A></form>
61     </body>
62 </HTML>
63 
CS
 1 using System;
 2 using System.Collections;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Web;
 7 using System.Web.SessionState;
 8 using System.Web.UI;
 9 using System.Web.UI.WebControls;
10 using System.Web.UI.HtmlControls;
11 
12 namespace CsvExport
13 {
14     /// <summary>
15     /// Background の概要の説明です。
16     /// </summary>
17     public class Background : System.Web.UI.Page
18     {
19         private void Page_Load(object sender, System.EventArgs e)
20         {
21             string code = (string)Request.Params["code"];
22             switch(code)
23             {
24                 case "A" :
25                     ot1();
26                     break;
27                 case "B" :
28                     ot2();
29                     break;
30             }
31         }
32 
33         private void ot1()
34         {
35             string strCsv = "1, 2, 3, 4";
36             Response.Clear(); 
37             Response.BufferOutput= false
38             Response.Charset="shift-jis";
39             Response.AppendHeader("Content-Disposition","attachment;filename=t1.csv"); 
40             Response.ContentEncoding=System.Text.Encoding.GetEncoding("shift-jis");
41             Response.ContentType = "application/octet-stream";
42             this.EnableViewState = false;
43             Response.Write(strCsv);
44             Response.End();
45         }
46 
47         private void ot2()
48         {
49             string strCsv = "A, B, C, D";
50             Response.Clear(); 
51             Response.BufferOutput= false
52             Response.Charset="shift-jis";
53             Response.AppendHeader("Content-Disposition","attachment;filename=t2.csv"); 
54             Response.ContentEncoding=System.Text.Encoding.GetEncoding("shift-jis");
55             Response.ContentType = "application/octet-stream";
56             this.EnableViewState = false;
57             Response.Write(strCsv);
58             Response.End();
59         }
60 
61         #region Web フォーム デザイナで生成されたコード 
62         override protected void OnInit(EventArgs e)
63         {
64             //
65             // CODEGEN: この呼び出しは、ASP.NET Web フォーム デザイナで必要です。
66             //
67             InitializeComponent();
68             base.OnInit(e);
69         }
70         
71         /// <summary>
72         /// デザイナ サポートに必要なメソッドです。このメソッドの内容を
73         /// コード エディタで変更しないでください。
74         /// </summary>
75         private void InitializeComponent()
76         {    
77             this.Load += new System.EventHandler(this.Page_Load);
78         }
79         #endregion
80     }
81 }
82 
HTML(setInterval调用关闭)
 1 <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="CsvExport.WebForm1" %>
 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
 3 <HTML>
 4     <HEAD>
 5         <title>WebForm1</title>
 6         <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
 7         <meta content="C#" name="CODE_LANGUAGE">
 8         <meta content="JavaScript" name="vs_defaultClientScript">
 9         <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
10         <script type="text/javascript">
11         <!--
12             var $ = function(objId) {
13                 return document.getElementById(objId);
14             }
15             window.onload = function() {
16                 $('btn1').onclick = CsvOutPut1;
17                 $('btn2').onclick = CsvOutPut2;
18                 $('btn3').onclick = CsvOutPut3;
19             }
20         
21             function CsvOutPut1() {
22                 $('ifr1').setAttribute('src''Background.aspx?code=A');
23                 setTimeout("$('ifr2').setAttribute('src', 'Background.aspx?code=B')"100);
24             }
25             
26             //説明:IE7はOpenした画面を自動にCloseできること、しかしIE6の方は自動にCloseできないで、手動でClose必要。
27             var subWin = null;
28             var res = null;
29             function CsvOutPut2() {
30                 subWin = window.open('Background.aspx?code=A','','height=0,width=0,top=8000,left=8000');
31                 res = self.setInterval("closeSubWin()"1000);
32                 setTimeout("document.getElementById('ifr2').setAttribute('src', 'Background.aspx?code=B')"100);
33             }
34             
35             function closeSubWin() {
36                 if (subWin != null && !subWin.closed) {
37                     subWin.close();
38                 } else {
39                     window.clearInterval(res);
40                     return;
41                 }
42             }
43             
44             function CsvOutPut3() {
45                 $('a1').click();
46                 $('a2').click();
47             }
48         //-->
49         </script>
50     </HEAD>
51     <body MS_POSITIONING="GridLayout">
52         <form id="Form1" method="post" runat="server">
53             <asp:Label id="Label2" style="Z-INDEX: 105; LEFT: 120px; POSITION: absolute; TOP: 64px" runat="server"
54                 Width="224px">IE6 IE7 OK</asp:Label>
55             <asp:Label id="Label3" style="Z-INDEX: 106; LEFT: 120px; POSITION: absolute; TOP: 104px" runat="server"
56                 Width="224px">IE7 OK</asp:Label><iframe id="ifr1" width="0" height="0"></iframe>
57             <iframe id="ifr2" width="0" height="0"></iframe><input id="btn1" style="Z-INDEX: 100; LEFT: 24px; POSITION: absolute; TOP: 16px" type="button"
58                 value="Button1"> <input id="btn2" style="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 56px" type="button"
59                 value="Button2"> <input id="btn3" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 96px" type="button"
60                 value="Button3"> <id="a1" href="Background.aspx?code=A" target="_blank"></A>
61             <asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 120px; POSITION: absolute; TOP: 24px" runat="server"
62                 Width="224px">IE7 OK</asp:Label><id="a2" href="Background.aspx?code=B"></A></form>
63     </body>
64 </HTML>
65 
posted on 2009-07-27 20:32  10cn.net  阅读(285)  评论(0编辑  收藏  举报