【问题标题】:Hiding Address bar in popup window在弹出窗口中隐藏地址栏
【发布时间】:2010-11-22 07:52:27
【问题描述】:

net 应用程序,我在其中使用一些弹出窗口来打开一些页面。为此,我正在使用这样的方法

private void OpenWindow(string Url, string height, string Width)
{
    try
    {
        string strScript = "";
        strScript += "<script language=\"javascript\">";
        strScript += "eval(\"popUpWindow('" + Url + "',0,0," + Width + "," + height + ",directories=no)\");";
        strScript += "</script>";
        lblScript.Text = strScript;
    }
    catch (Exception ex)
    {
        LogError.Log(ex);
        throw;
    }
}

JavaScript 函数如下:

var popUpWin = 0;

function popUpWindow(URLStr, left, top, width, height, windowName) {
    left = (screen.width / 2) - width / 2;
    top = (screen.height / 2) - height / 2;
    if (popUpWin) {
        if (!popUpWin.closed)
            popUpWin.close();
    }
    popUpWin = open(URLStr, windowName, 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top + '');
    popUpWin.focus();
}

现在它可以正常显示地址栏了。但我的要求是我必须在所有弹出窗口中隐藏地址栏。这可能吗?请提供一种解决方案来提供帮助。谢谢你..

【问题讨论】:

  • 没有适用于所有浏览器的单一解决方案
  • 但我需要适用于 ie 的解决方案。

标签: c# javascript asp.net popup address-bar


【解决方案1】:

不,这是不可能的。 IIRC 安全功能是在 IE 6 中引入的。

以下是一些较早的讨论:

How can I hide the address bar in a modal dialog?
Can't hide status bar when doing windows.open on IE8
Popup window, how to Hide URL bar in IE8

【讨论】:

    【解决方案2】:

    这取决于您尝试使用的浏览器。

    较旧的浏览器会允许这样做,但现在几天后,浏览器将继续显示地址栏。这样做的原因之一是更难让用户认为您展示的是真实的应用程序(病毒扫描程序?!?)而不是网站。

    【讨论】:

      【解决方案3】:

      无论如何使用System.Text.StringBuilder 而不是字符串连接。

      var sb = new StringBuilder();
      sb.Append("<script language=\"javascript\">");
      sb.AppendFormat("eval(\"popUpWindow('{0}',0,0,{1},{2},directories=no)\");", url, width, height);
      sb.Append("</script>");
      lblScript.Text = sb.ToString();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-12
        • 2013-04-02
        • 2022-12-31
        • 2018-07-21
        • 2012-06-13
        • 1970-01-01
        相关资源
        最近更新 更多