首页 > 解决方案 > 无法使用 c#/ASP.Net 在 Chrome 中打开弹出窗口

问题描述

我有基于文件夹内容动态构建一系列超链接的代码。当我运行代码并单击链接时,会弹出一个窗口,但它是空白的。这是使用 Chrome 的 ASP.Net 4.6.1 网页中的 C#。这是我的代码:

        TableRow newRow = new TableRow();
        string foldername = Convert.ToString(Request.QueryString["oid"]) + "\\";
        string pathString = Server.MapPath("~/Files/");
        string completePath = Path.Combine(pathString + foldername);
        if (Directory.Exists(completePath))
        {
            string[] files = Directory.GetFiles(completePath);
            int cellCount = 0;
            foreach (string foundfile in files)
            {
                TableCell newCell = new TableCell();
                newCell.BorderColor = Color.Black;
                newCell.BorderWidth = Unit.Parse("1px");
                string filename = Path.GetFileName(foundfile);
                HyperLink hl = new HyperLink();
                hl.NavigateUrl = completePath + filename;
                hl.Text = filename;
                hl.Target = "_blank";
                hl.Attributes.Add("onclick", "window.open(this.href, 'child', 'height=400, width=600,scrollbars'); return false");
                if (cellCount == 0 || (cellCount % 3) == 0)
                {
                    newRow = new TableRow();
                    taSpecs.Rows.Add(newRow);
                }
                newCell.Controls.Add(hl);
                newRow.Cells.Add(newCell);
                cellCount++;
            }
        }

文件存在,如果我将 URL 从链接之一复制到文件资源管理器,它会毫无问题地打开文件。Chrome 已关闭弹出窗口阻止程序。我究竟做错了什么?

标签: c#asp.netgoogle-chromehyperlinkpopupwindow

解决方案


推荐阅读