pepe
pepe

Reputation: 9919

How do I programatically force Chrome to show PDF file in a new tab?

I am aware that one can do this manually (hold Ctrl down when clicking the PDF link).

But I need a solution like this:

-- when a user clicks on the link that generates the PDF, Chrome will either display the PDF in-browser in a new tab

or

-- override that behavior and show the download dialog.

Any ideas?

MORE INFO:

On my page there is a form that is submitted to generate the PDF. The form is submitted using a combination of anchor and jquery submit.

The PDF is then returned to the browser - on FF I get the download dialog, but on Cr I get the PDF loaded in the same tab.

//form elements

<a id="submit" target="_blank" href="http://example.com/#">download pdf</a>


<script>

$('#submit').click(function(e) {

    e.preventDefault();

    $('#lost_form').submit();

});

</script>

Upvotes: 5

Views: 11964

Answers (2)

krishna singh
krishna singh

Reputation: 1073

onclick open a new window, with your PDF path in this url

http://docs.google.com/gview?url=<?php echo $pdffilefath;?>&embedded=true

Upvotes: 2

Matt Ball
Matt Ball

Reputation: 359996

In the link to the PDF, use target="_blank", like so:

<a href="//path/to/document.pdf" target="_blank">PDF link text</a>

If you want to make the PDF download instead of open in-browser, you need to set the Content-Disposition HTTP response header to something like

Content-Disposition: attachment; filename=document.pdf

Upvotes: 6

Related Questions