Solved

Open file in new window

Posted on 2013-05-21
7
751 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 51

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 51

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Author Comment

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

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 51

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There is a huge demand for CodeIgniter among the PHP web developers due to its dynamic features and benefits these days. It is one of most popular and agile open source PHP framework for creating robust web applications in PHP web development field.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now