开发者

IE9 - Information Bar to download file appears on Parent Window; not current

Original Post

One of the features of my Web App is that it prints reports. These reports require a pop-up window allowing the user to refine the parameters of the report. This cannot change.

Pre-IE9, when the user clicked my "Preview" button on the pop-up window, they would get a dialog like this once the report rendered:

IE9 - Information Bar to download file appears on Parent Window; not current

This is easy and intuitive to my clients.

However, after upgrading to IE9, the Message Bar (Information Bar/Download Bar) whatever it's called, shows in the PARENT window of the pop-up:

IE9 - Information Bar to download file appears on Parent Window; not current

In order to download or open the report, the user is now required to close the pop-up window and then select the appropriate action on the Download Bar.

This is a pretty frustrating work-around.

I've looked for ways on the net to either show the the Download Bar on the pop-up window (preferred), revert to the old dialog, or remove it all together.

No solutions yet. If anyone has any IE solutions/work-arounds, please post them.


Update

UPDATE ON THIS UPDATE The steps below do expose a bug, but not one related to my issue as it happens on all versions of IE. I think it's close but I will need to look test more to get the precise issue.

Ok, so I looked deeper in the code and whittled it down enough to produce an issue. It's actually different than my original issue (grrr), but perhaps related.

What you need:

  • Windows 7
  • IIS 7.0

Create the following four files:

PageOne.htm with the following contents:

<html>
    <head>
        <script type="text/javascript">
            window.dialog = new Object();

            var myFunc = function() { window.alert('hello')};

            function test(){
                window.dialog.open('DummyDialog.htm',myFunc,false);
                };


            window.dialog.open = function(sUrl, fpReturn, bNoResize) {

                window.dialog.__returnFunction = fpReturn;
                window.dialog.returnValue = null;

                window.dialog.arguments = new Array();
                for (var x = 2; x < arguments.length; x++) {
                    window.dialog.arguments[x - 2] = arguments[x];
                }

                window.dialog.arguments[window.dialog.arguments.length] = window;

                sUrl += new Date().getTime().toString(); 


                var sFeatures;
                var nWidth = 500;    var nHeight = 500;    var nLeft = 100;    var nTop =  100;

                if (window.dialog.position) {
                    nLeft = window.dialog.position.left;
                    nTop = window.dialog.position.top;
                    window.dialog.position = null;
                } 

                if (sUrl.indexOf("?") != -1) {
                    var pairs = sUrl.split("?")[1].split("&");
                    var aValue, pos;
                    for (var i = 0; i < pairs.length; i++) {
                        if (pairs[i].toUpperCase().indexOf("SIZE") == 0) {
                            aValue = pairs[i].split("=")[1].split(",");
                            if (aValue.length == 2) {
                                nWidth = parseInt(aValue[0]);
                                nHeight = parseInt(aValue[1]);
                                break;
                            } else if (aValue.length == 4) {
                                nWidth = parseInt(aValue[0]);
                                nHeight = parseInt(aValue[1]);
                                nLeft = parseInt(aValue[2]);
                                nTop = parseInt(aValue[3]);
                                break;
                            }
                        }
                    }
                }

                nTop -= 1;

                sFeatures = "";

                window.dialog.arguments._gotoURL = sUrl;
                window.dialog.arguments._dialogTitle = 'my title';
                window.dialog.returnValue = window.showModalDialog("DummyDialog.htm", window.dialog.arguments, sFeatures);
            };
        </script>
    </head>
    <body>
        <a href="#" onclick="test();">Test Window</a>
    </body>
</html>

DummyDialog.htm with the following contents:

<html>
    <head>
        <script type="text/javascript">
            window.dialog = new Object();

            var myFunc = function() { window.alert('hello')};

            function test(){
                window.dialog.open('DummyDialog.htm',myFunc,false);
                };


            window.dialog.open = function(sUrl, fpReturn, bNoResize) {

                window.dialog.__returnFunction = fpReturn;
                window.dialog.returnValue = null;

                window.dialog.arguments = new Array();
                for (var x = 2; x < arguments.length; x++) {
                    window.dialog.arguments[x - 2] = arguments[x];
                }

                if (true) {//if (is.ie) {
                    window.dialog.arguments[window.dialog.arguments.length] = window;
                }

                sUrl += new Date().getTime().toString();
                // in pixels
                var sFeatures;
                var nWidth = 500;
                var nHeight = 500;
                var nLeft = 100;
                var nTop =  100;

                if (window.dialog.position) {
                    nLeft = window.dialog.position.left;
                    nTop = window.dialog.position.top;
                    window.dialog.position = null;
                } 

                if (sUrl.indexOf("?") != -1) {
                    var pairs = sUrl.split("?")[1].split("&");
                    var aValue, pos;
                    for (var i = 0; i < pairs.length; i++) {
                        if (pairs[i].toUpperCase().indexOf("SIZE") == 0) {
                            aValue = pairs[i].split("=")[1].split(",");
                            if (aValue.length == 2) {
                                nWidth = parseInt(aValue[0]);
                                nHeight = parseInt(aValue[1]);
                                break;
                            } else if (aValue.length == 4) {
                                nWidth = parseInt(aValue[0]);
                                nHeight = parseInt(aValue[1]);
                                nLeft = parseInt(aValue[2]);
                                nTop = parseInt(aValue[3]);
                                break;
                            }
                        }
                    }
                }

                nTop -= 1;      
                sFeatures = "";
                window.dialog.arguments._gotoURL = 'download.aspx?file=MyTestFile.txt';
                window.dialog.arguments._dialogTitle = 'my title';//window.getTitle();
                window.dialog.returnValue = window.showModalDialog('download.aspx?file=MyTestFile.txt', window.dialog.arguments, sFeatures);

            };
        </script>
    </head>
    <body>
        <a href="#" onclick="test();">Test Window</a>
    </body>
</html>

download.aspx with the following contents:

<%@ Page language="vb" runat="server" explicit="true" strict="true" %>
<script language="vb" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
    Dim strRequest As String = Request.QueryString("file") '-- if something was passed to the file querystring
    If strRequest <> "" Then 'get absolute path of the file
        Dim path As String = Server.MapPath(strRequest) 'get file object as FileInfo
        Dim file As System.IO.FileInfo = New System.IO.FileInfo(path) '-- if the file exists on the server
        If file.Exists Then 'set appropriate headers
            Response.Clear()
            Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)
            Response.AddHeader("Content-Length", file.Length.ToString())
            Response.ContentType = "application/octet-stream"
            Response.WriteFile(file.FullName)
            Response.End 'if file does not exist
        Else
            Response.Write("This file does not exist.")
        End If 'nothing in the URL as HTTP GET
    Else
        Response.Write("Please provide a file to download.")
    End If
End Sub
</script>

MyTestFile.txt with the following contents:

<Root>
  <Tag>Hello World</Tag>
</Root>

Now do the following:

  1. Drag all four files to your IIS directory and navigate to PageOne.htm.
  2. Click Test Window (DummyDialog.htm should popup)
  3. Click the hyperlink in that PopUp (this should take you to http://localhost/download.aspx?file=MyTestFile.txt)

开发者_Python百科What's supposed to happen is that you should be prompted for download. Instead, what I get is a blank window that does nothing. See below:

IE9 - Information Bar to download file appears on Parent Window; not current

If you take that same url http://localhost/download.aspx?file=MyTestFile.txt and paste it directly into a new IE window or, alternatively, run the same steps above in Firefox, you'll be prompted for download.

So why would a popup in IE bring nothing but a blank window?


One solution would be to not use a pop-up window, but to use a pop-in window like a jQuery UI dialog. This would give you much more control over things, and would also keep them in the same window so that your users don't miss the ie9 download bar.

Another option might be to have the parameters determined on a new page, rather than a pop-up window.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜