34

I have a hyperlink with contains third party website link. I want to open this link in new tab with print command. How can i do this? Suppose:

<a href="www.google.com" target="_blank">Print</a>

Note: I know how to open a link in new TAB/Window. I want to know how to open with PRINT DIALOG.

Sandy
  • 6,285
  • 15
  • 65
  • 93

6 Answers6

66

You could try something like this:

<a href="javascript: w=window.open('http://yoursite.com/LinkToThePDF.pdf'); w.print(); w.close(); ">​​​​​​​​​​​​​​​​​print pdf</a>
Nikola
  • 14,888
  • 21
  • 101
  • 165
7

This method works well for me.

<a href="/url/" onclick="window.open(this.href).print(); return false">
AMIN
  • 31
  • 4
Collin Anderson
  • 14,787
  • 6
  • 68
  • 57
3

There is no way for a website to cause a browser to load a third party website and display the print dialog for it automatically.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
3
<img src="print.png" style="cursor:hand" onclick="window.frames['pact'].print();"><iframe name="pact" src="pact.pdf" width="0" height="0" frameborder="0"></iframe>
Vitalicus
  • 1,188
  • 13
  • 15
0

This absolutely worked for me. I'm coding a site in Angular 6.

<a href="doc.pdf" onClick="window.print(); return false">Print</a>

Here's my source (enter link description here) but watch out for double quotes in the originak source.

:)

Mr. Benedict
  • 809
  • 2
  • 10
  • 15
-4

This is depend on your browsers, you can enable the tab for new link, If you are using Firefox you can enable the tab using Firefox -> Options -> options -> open a new windows in a new tab instead option

Sujanth
  • 613
  • 1
  • 6
  • 12
  • Thanks for quick response.I just want to know open in new tab with PRINT DIALOG. – Sandy Sep 05 '12 at 08:23
  • do you want to keep the PRINT text on the new tab or previous tab? – Sujanth Sep 05 '12 at 08:40
  • do not want to keep this text in new tab only print dialog. – Sandy Sep 05 '12 at 08:49
  • You can't set the print dialog, because the print command is being sent directly from the PDF application and not the browser(which the JS interacts with) – Sujanth Sep 05 '12 at 09:08
  • If you are using php, javascript you can.PDFs have Javascript support. you need to have auto print capabilities when a PHP-generated PDF was created and you need to use FPDF to get it to work: http://www.fpdf.org/en/script/script36.php – Sujanth Sep 05 '12 at 09:11
  • check this one also http://www.ehow.com/how_7352227_use-javascript-print-pdf.html – Sujanth Sep 05 '12 at 09:15