简体   繁体   English

Window.Open替换失败

[英]Window.Open Replace fails

I have a page with a master page. 我有一个包含母版页的页面。 On the page is some javascript to open a new window.... 页面上有一些JavaScript可以打开新窗口。

         function PopWin() {
        var ddl = document.getElementById("DropDownList1");
        var strField = "";
        if (ddl != null && ddl.selectedIndex > -1 && ddl.options[ddl.selectedIndex] != null)
            strField += ddl.options[ddl.selectedIndex].text;
        var win = window.open('Report.aspx?item=' + strField, 'Popup', 'width=1000,height=700,resizable=yes,top=5,left=5,scrollbars=yes,status=yes', false);
        win.focus();
    }

And the button that calls the javascript: 以及调用javascript的按钮:

 <asp:Button ID="btnReport" runat="server" Text="Report" UseSubmitBehavior="False"
  OnClientClick="Popwin();" />

The format for the javascript is window.open(URL,name,specs,replace). JavaScript的格式为window.open(URL,name,specs,replace)。
The problem is that even though the replace is set to false, it still replaces the current window. 问题是,即使将replace设置为false,它仍然会替换当前窗口。 It needs to open a completely new window leaving the previous one in tact. 它需要打开一个全新的窗口,使之前的窗口保持原样。

This works on my pc while developing using VS 2010 and IE 10. Placing it on the staging server it fails and fails on the production server as well. 在使用VS 2010和IE 10开发时,这在我的PC上有效。将其放在登台服务器上会失败,在生产服务器上也会失败。

I inherited the entire application and did a LOT of fixing. 我继承了整个应用程序,并进行了大量修复。 The old code worked. 旧代码有效。
And comparing the old with the new, it's the same, except for adding the replace param to false. 并将新旧参数进行比较,除了将replace参数添加到false之外,其他操作都是相同的。

Only other difference is I also added and update panel. 我还添加和更新了面板,这只是其他区别。 Yes, I removed it and it still failed. 是的,我将其删除,但仍然失败。 I even cleared the browser cache and it still failed. 我什至清除了浏览器缓存,但仍然失败。 I looked at the source in the browser and the new javascript code is there. 我在浏览器中查看了源代码,并找到了新的javascript代码。

Also removed the win.focus and it still replaces the old window. 还删除了win.focus,它仍然替换了旧窗口。

It also fails in FF while on the server. 在服务器上,它在FF中也失败。

The replace argument is not what you think it's for. replace参数不是您想要的。 A quote from MSDN : 来自MSDN的报价:

Boolean that specifies whether the url creates a new entry or replaces the current entry in the window's history list. 布尔值 ,指定url是创建新条目还是替换窗口的历史记录列表中的当前条目。 This parameter only takes effect if the url is loaded into the same window. 仅当URL加载到同一窗口中时,此参数才生效。

To open several pop-ups, you need to use different name for each new pop-up. 要打开多个弹出窗口,您需要为每个新的弹出窗口使用不同的名称。 You could keep book of opened windows in an external variable, or maybe use strField , anyway add something to 'Popup' -argument to make it unique. 您可以将打开的窗口的书保留在一个外部变量中,或者使用strField ,无论如何向'Popup'参数中添加一些内容以使其独特。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM