简体   繁体   中英

jQuery not loading in new IE window

First off, I'd like to preface this question by expressing how unfathomably much I hate IE. Sometimes I wake up in the middle of the night from IE-induced nightmares, causing me to leap out of my bed screaming and sometimes mercilessly beating anyone around me. My neighbors hate it. Just hearing "IE" makes me cringe. But I digress.

Anyway, I have an page on my MVC web app which launches a new page via AJAX (through a different view) and displays a chart. The problem, however, is that when I open the new window, in IE only, the scripts aren't loaded (or at least they aren't loaded in time?) But I get "jQuery is undefined" on the first reference to the jQuery object.

On a reload, however, everything loads just fine. Any idea what might cause scripts not to load in IE? Chrome and FF work fine.

Here's the ajax call that I use for the new window:

$.ajax({
                type: "POST",
                url: actionURL + qs,
                data: $(this).serialize(),
                success: function (outputString) {
                    //$("#reportJSON").html(outputString).fadeIn();
                    var contentFromFirstPage = document.getElementById('reportArea').innerHTML;
                    var printContent = outputString;
                    var windowUrl = 'about:blank';
                    var uniqueName = new Date();
                    var windowName = 'Print' + uniqueName.getTime();
                    var printWindow = window.open(windowUrl, windowName, 'scrollbars=1,menubar=1,height=800,width=600,resizable=1');
                    printWindow.document.write(printContent);
                    printWindow.focus();
                    //printWindow.document.close();

                }
            }).error(function (response) {
                alert("something went wrong here with PrintPreview!!!" + response);
            });

and here is the action that the ajax calls:

public ActionResult PrintPreview(string reportId, string date, string dateFrom, string dateTo)
        {
            Reports reports = new Reports
            {
                ReportId = Convert.ToInt64(reportId),
                Date = Convert.ToDateTime(date),
                DateFrom = Convert.ToDateTime(dateFrom),
                DateTo = Convert.ToDateTime(dateTo),
                AvailableReports = this.FetchAvailableReports()
            };



            reports.AvailableReports = this.FetchAvailableReports();
            reports.SelectedReport = this.FetchReportLayout(reports.ReportId);
            reports.DynamicGridDataSource = this.FetchReportGrid(reports);
            reports.DynamicChartDataSource = this.FetchReportChart(reports);

            return renderViewToString("PrintPreview", reports);
        }

OK, from the discussions I'm going to take a punt at an answer!

Thinking about it, and how it's often with the pain caused by IE, it just a bug / implimentation difference in the raw code, and without actually being able to rewrite the browser behaviour you're in essence out of luck - much like many of the required CSS hacks just for IE.

However, from looking at the code you've posted, I'm assuming the ajax call take the current page, does some stuff with it and returns a print friendly formatted load of HTML? This HTML is then printed into the new window...

Now the only way around this I can think is to go for a slight change to your architecture; The new window will need to open a page, and the ajax call is made on that page to popuate the contents.

However, I would say, IMHO the real use of Ajax calls is that you can remain in the same window, page, and contents without a refresh. As you're opening a new window, I'd have thought just a straight URL with the report ID, date, DateFrom and DateTo in the querystring would work better?

If it's a time issue (the report takes a while to generate), then personally I'd just pass the contents into the new window, and have the new window script inject that into a div .

And then look at this as a Cross Browser solution, rather than using a setTimeout IE hack ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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