Solved

Open file in new window

Posted on 2013-05-21
7
758 Views
Last Modified: 2013-05-21
I have jquery function which calls an action GetReport which returns a pdf file
This is the Action
 return File(renderedBytes, mimeType);

Open in new window


This is the function
function showReport() {
        var clinic = $("#SelectedClinic").val();
        var date = $("#SelectedDate").val();
      var url = "/Reports/GetReport";
         $.get(url, { SelectedClinic: clinic, SelectedDate: date }, function (data) {
             $("#outPut").html(data);
         });
    }

This is the result
result
I would ideally like to open the pdf file in a new window or tab.
I might also like to show the file DIV $("#outPut") but my real question is how to open it in a new window.


By the way this works
@Html.ActionLink("View in new tab","GetReport","Reports", new {SelectedClinic = "Galway"  }, new { target="_blank" })
but i cannot set the SelectedClinic parameter without doing a post.

The SelectedClinic should come from the dropdown.

Thanks
Eamon
0
Comment
Question by:Eamon
  • 4
  • 3
7 Comments
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 39183982
You will need to open the new window first and have your script run in that.
0
 
LVL 1

Author Comment

by:Eamon
ID: 39183986
$("#outPut").html(data);
in a new window will still not display the report.
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 39184048
But why are you doing it this way

Why not just have

<a href="pathtopdf/file.pdf" _target="blank">Link text</a>

Or

<a href="pathtopdfcontainer.html" _target="blank">Link text</a> and then have the pdf load in this file (or script)?
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 1

Author Comment

by:Eamon
ID: 39184082
The action GetReport generates the report and returns a file
0
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39184142
Ok I think I understand - you want to open a doc based on the value of the drop down and have it open in a new window?

Can you not do something like the following
function showReport() {
  var clinic = $("#SelectedClinic").val();
  var date = $("#SelectedDate").val();
  var url = "/Reports/GetReport";
  window.open(url + '?SelectedClinic=' + clinic + '&SelectedDate' + date, '_blank');
}

Open in new window

0
 
LVL 1

Author Comment

by:Eamon
ID: 39184190
Thank you
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 39184558
you are welcome - thanks for the points.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question