开发者

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>


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


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜