Solved

Open file in new window

Posted on 2013-05-21
7
763 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 57

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 57

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

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

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 57

Expert Comment

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

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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 invoke it on a web page. 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.: (CODE)

690 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