0

I have a handler (ashx) and I would like to send a file to browser to the new tab.

I know that I can use the JavaScript (when I use the JS, the browser shows the message about blocking pop-up - I would like to avoid this message), but I would like to do this by Response from my handler. Is there any way?

I tried this, but this is open the PDF in the same window

  context.Response.Clear();
  context.Response.ClearHeaders();
  context.Response.ContentType = "application/pdf";
  context.Response.BinaryWrite(buffer);

I am calling the handler from Ajax:

            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "Default.aspx/AcceptFormData",
                data: "{'funcParam': " + JSON.stringify(data) + "}",
                dataType: "json",
                success: function (msg) {
                    window.location = "ashx/GetFile.ashx";

Thanks

Lubos Marek
  • 178
  • 1
  • 3
  • 13

1 Answers1

-1

Try window.open("ashx/GetFile.ashx");

As a side note, it is a user preference whether to open a new tab versus a new window. See Open a URL in a new tab (and not a new window) using JavaScript

Edit: If your intent is to avoid the popup blocker, the general rule seems to be that the popup blocker will only allow window.open() during processing of a direct user event. You have a few options:

  • Make your ajax call synchronous.
  • Present a modal or similar page element to the user during the ajax callback with a link or button to open the document and call window.open() during the click event.

Documentation: MDN - Window.open()

Community
  • 1
  • 1
JSF
  • 324
  • 2
  • 12