简体   繁体   English

Window.Open() 正在更改 Internet Explorer 上的页面布局

[英]Window.Open() is changing the page Layout on Internet Explorer

I have a page in asp.net called Home.aspx .我在 asp.net 中有一个名为Home.aspx的页面。 It uses a masterpage and also have a button that is calling:它使用一个母版页,还有一个按钮调用:

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

Result: The new tab is open with page2.aspx and if you return to Home.aspx , the page layout is modified, the central <div> is moved to the left of page.结果:新标签页用page2.aspx打开,如果您返回Home.aspx ,页面布局被修改,中央<div>移动到页面左侧。

What can i do to solve this problem?我能做些什么来解决这个问题? Remember that this is occurring only on Internet Explorer, Firefox works normally!请记住,这仅在 Internet Explorer 上发生,Firefox 正常工作!

Thanks a lot.非常感谢。

Not going into the merit on why are you doing that, your Response.Write is likely killing HTML/CSS/JS output in the Home.aspx page and preventing it from loading properly.不考虑你为什么这样做的优点,你的Response.Write可能会杀死 Home.aspx 页面中的 HTML/CSS/JS 输出并阻止它正确加载。 Try using:尝试使用:

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

Instead of the Response.Write, so as soon as the page loads it will open your window.而不是 Response.Write,所以一旦页面加载它就会打开你的窗口。

Generally if you want to write scripts from the code behind ScriptManager is your friend.通常,如果您想从ScriptManager背后的代码编写脚本,则是您的朋友。 Startup scripts happen after prerender, unload scripts happen on close and you can set them based on events like resize.启动脚本在预渲染后发生,卸载脚本在关闭时发生,您可以根据调整大小等事件设置它们。

That your div moves is related to the page turn and not the specific button's server code.您的 div 移动与翻页有关,而不是特定按钮的服务器代码。 Using使用

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

with an onclientclick="mybutton" in your button asp tag avoids the postback in this instance.在你的按钮 asp 标签中使用 onclientclick="mybutton" 避免了这种情况下的回发。 Beyond that you may have improper css or code that fires on page turn which will still move your div as soon as you postback.除此之外,您可能有不正确的 css 或在翻页时触发的代码,这些代码在您回发后仍会移动您的 div。

In case somebody will find it useful, here is the exact answer which worked for me:如果有人会发现它有用,这里是对我有用的确切答案:

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

So, in the OP case, instead of所以,在 OP 的情况下,而不是

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

that would work:那会起作用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Internet Explorer 8、9 window.open问题 - Internet Explorer 8, 9 window.open issue javascript window.open 应该在 Internet Explorer 中打开一些 url - javascript window.open should open some urls in internet explorer JavaScript,window.open,干净的URL和Internet Explorer 10 - JavaScript, window.open, clean url's and Internet Explorer 10 Javascript“window.open”代码在Internet Explorer 7或8中不起作用 - Javascript “window.open” code won't work in Internet Explorer 7 or 8 如何从Internet Explorer 11中的window.open返回值? - How to return value from window.open in Internet Explorer 11? 你如何获得window.open在Internet Explorer 7中工作? - How do you get window.open to work in internet explorer 7? Internet Explorer 11没有javascript window.open()函数支持的此类接口 - Internet Explorer 11 no such interface supported with javascript window.open() function 打开 Intranet 网站时 Internet Explorer 11 上的 Javascript window.open() 无法正常工作 - Javascript window.open() on Internet Explorer 11 when open intranet website not work correctly Internet Explorer不处理由window.open打开的窗口抛出的任何事件 - Internet Explorer not handling any event thrown by window opened with window.open 设置window.open()的HTML在Internet Explorer中产生奇怪的样式问题 - Setting HTML of window.open() producing strange styling issues in Internet Explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM