【问题标题】:asp link to open image on displayed image在显示的图像上打开图像的 asp 链接
【发布时间】:2018-06-17 00:50:10
【问题描述】:

我在转发器控件中有一个 asp 图像,我使用此处找到的标记答案来获取它,以便它链接到实际文件:

Asp:Image with Link

具体来说,我用一个 asp:hyperlink 包围它:

<asp:hyperlink id="link" runat="server">
   <asp:image id="img" runat="server" imageurl="..." />
</asp:hyperlink>

这个解决方案非常有效。但是,当我尝试在 IE 中单击链接时,它会立即下载图像,然后在底部提示我打开或保存文件的选项。

有没有办法让该超链接在新页面上打开图像?

【问题讨论】:

  • 您想单击该图像并在新页面中打开该图像吗?新标签?
  • 我希望它弹出,最好是,但除了即时下载之外,我什么都不会。相同的页面,新的页面,无论你得到什么。而目标的想法并没有奏效。

标签: c# asp.net image hyperlink


【解决方案1】:

如果可以使用js:

<asp:HyperLink ID="link" runat="server">
    <asp:Image ID="img" runat="server" 
        ImageUrl="~/images/app/your-img.png"
        onclick="openWinPopUp(this.src)" />
</asp:HyperLink>

<script>
    function openWinPopUp(URL, w, h, t, l) {
        var wdh = (w == null || w == "" || w == "undefined") ? 250 : w;
        var hgh = (h == null || h == "" || h == "undefined") ? 160 : h;
        var tp = (t == null || t == "" || t == "undefined") ? 200 : t;
        var lft = (l == null || l == "" || l == "undefined") ? 100 : l;
        window.open(URL, "blank", "toolbar=no,location=no,directories=no," +
            "status=no,menubar=no,scrollbars=yes," +
            "resizable=no,copyhistory=no," +
            "width=" + wdh + ", height=" + hgh + ", left =" + lft + "," +
            "top = " + tp + ";");
    }
</script>

在 MS Edge 上测试。

【讨论】:

    猜你喜欢
    • 2020-10-06
    • 2023-04-01
    • 1970-01-01
    • 2013-07-12
    • 2018-03-17
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 2013-12-14
    相关资源
    最近更新 更多