【问题标题】:Window.Open() is changing the page Layout on Internet ExplorerWindow.Open() 正在更改 Internet Explorer 上的页面布局
【发布时间】:2013-08-09 06:49:22
【问题描述】:

我在 asp.net 中有一个名为 Home.aspx 的页面。它使用母版页,还有一个正在调用的按钮:

Response.Write("<script> window.open('page2.aspx','_blank'); </script>")

结果:新标签页以page2.aspx打开,如果返回Home.aspx,页面布局被修改,中心&lt;div&gt;被移动在页面的左侧。

我能做些什么来解决这个问题?请记住,这只发生在 Internet Explorer 上,Firefox 可以正常工作!

非常感谢。

【问题讨论】:

    标签: javascript html asp.net vb.net dom


    【解决方案1】:

    不讨论你为什么这样做的优点,你的Response.Write 可能会杀死 Home.aspx 页面中的 HTML/CSS/JS 输出并阻止它正确加载。尝试使用:

    ScriptManager.RegisterStartupScript(typeof(Page),
                "OpenPage2", "window.open('page2.aspx','_blank');", true);
    

    而不是 Response.Write,所以一旦页面加载它就会打开你的窗口。

    【讨论】:

    • 谢谢@F.Aquino,我会测试并返回结果!!
    【解决方案2】:

    一般来说,如果你想用ScriptManager 后面的代码编写脚本,你的朋友就是你。启动脚本在预渲染后发生,卸载脚本在关闭时发生,您可以根据调整大小等事件进行设置。

    您的 div 移动与翻页有关,而不是特定按钮的服务器代码。使用

        <script language="javascript" type="text/javascript">
            function mybutton() {
                window.open('page2.aspx', '_blank');
                return false;
            }
        </script>
    

    在您的按钮 asp 标记中使用 onclientclick="mybutton" 可以避免这种情况下的回发。 除此之外,您可能有不正确的 css 或在翻页时触发的代码,一旦您回发,它们仍会移动您的 div。

    【讨论】:

      【解决方案3】:

      如果有人觉得它有用,这里是对我有用的确切答案:

      http://www.schnieds.com/2008/06/css-lost-on-postback-in-aspnet.html

      所以,在 OP 的情况下,而不是

      Response.Write("<script> window.open('page2.aspx','_blank'); </script>")
      

      会起作用的:

              String myScript = "<script> window.open('page2.aspx','_blank'); </script>";
              Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", myScript);
      

      【讨论】:

        猜你喜欢
        • 2012-05-30
        • 1970-01-01
        • 1970-01-01
        • 2016-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-31
        相关资源
        最近更新 更多