Solved

Open file in new window

Posted on 2013-05-21
7
761 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
toggle content 12 39
Execute jQuery after Function 4 37
How do I allow for non standard CSV file 9 41
Shared Service Environment 2 53
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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.…
The viewer will learn how to dynamically set the form action using jQuery.
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)

738 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