• javascript 返回新窗口的值


    <HTML>
        <HEAD>
            <title>NewOpen</title>
            <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" Content="C#">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
            <script language="javascript">
             function OpenImage()
             {
                window.open("Open.aspx","sdf","width=600,height=400,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
                return false;
             }
            </script>
        </HEAD>
        <body>
            <form id="Form1" method="post" runat="server">
                <a href="javascript:" onclick="return OpenImage();">打開新窗口</a><br>
                <asp:Image id="img1" runat="server" ImageUrl="image/001.gif"></asp:Image>
            </form>
        </body>
    </HTML>

    Open.aspx
    <HTML>
        <HEAD>
            <title>Open</title>
            <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" Content="C#">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
            <script language="javascript">
            function PI(url)
            {
                var a = opener.document.getElementById("img1");
                a.src = url;
                window.close();
            }
            </script>
        </HEAD>
        <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
            </form>
        </body>
    </HTML>

    Open.aspx.cs
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    namespace WebApplication1
    {
        /// <summary>
        /// Summary description for Open.
        /// </summary>
        public class Open : System.Web.UI.Page
        {

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                //
                // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                //
                InitializeComponent();
                base.OnInit(e);
            }
           
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {   
                this.Load += new System.EventHandler(this.Page_Load);
            }
            #endregion
       

            private void Page_Load(object sender, System.EventArgs e)
            {
                // 在此处放置用户代码以初始化页面
                if(!IsPostBack)
                {
                    Display();
                }
            }


            private void Display()
            {
                Response.Write("<table cellpadding=0 cellspacing=0 border=0 align='center' width='100%'><tr>");
                string appUrl;
     
                //得到应用程序路径
                if (Request.ApplicationPath == "/")
                    appUrl = Request.ApplicationPath;
                else
                    appUrl = Request.ApplicationPath + "/";
      
                Response.Write(imageFileLocation);
                string appPath = HttpContext.Current.Request.PhysicalApplicationPath;//获得应用程序物理路径
                string imageFolderPath = appPath + "image";//获得头像目录
                string[] filesArray = System.IO.Directory.GetFiles(imageFolderPath,"*");//得到所有的头像图片文件
                int i = 0;//用他来做循环,每行输出8个头像图片
                foreach(string imageFile in filesArray)
                {
                    string imageFileName = imageFile.Substring(imageFile.LastIndexOf("\\")+1);//取的图片的真实名字,不包含路径
                    string imageFileLocation = appUrl.Substring(appUrl.LastIndexOf("\\")+1);
                    //取得头像图片路径
                    imageFileLocation += "image";
                    imageFileLocation += "/";
                    imageFileLocation += imageFileName;
                    string str = "<td align='center' width='25%'>"+"<a href=javascript:PI('"+imageFileLocation+"')><img border='0' src='"+imageFileLocation+"'></a>"+"</td>";
                    Response.Write(str);
                    i++;//每执行一次i加1
                    if(i%5==0)
                    {
                        Response.Write("</tr><tr>");//如果已经是5个头像了,就换行
                    }
                }
                Response.Write("</tr></table>");
            }
        }

    }
  • 相关阅读:
    idea 编程字体推荐
    推荐!国外程序员整理的系统管理员资源大全
    jquery阻止事件冒泡的3种方式
    web前端打印总结
    前端打印插件
    object实现小老鼠交互
    前端性能优化(DOM篇)
    输入框获得焦点时外边框颜色改变
    webstorm配置scss自动编译路径
    微信开发测试号配置
  • 原文地址:https://www.cnblogs.com/Bluer/p/613388.html
Copyright © 2020-2023  润新知