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.

6 Answers 6

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>
4
  • 2
    I have a web PDF link. i want to open this link in new tab. I can open it in new tab. New tab now display PDF file in browser. Now i want to open this link in new tab with Print Dialog Open.
    – Sandy
    Sep 5, 2012 at 8:52
  • 1
    Try if this works then: <a href="javascript: w=window.open('http://yoursite.com/LinkToThePDF.pdf'); w.print(); w.close(); ">​​​​​​​​​​​​​​​​​print pdf</a>
    – Nikola
    Sep 5, 2012 at 8:56
  • 9
    I found that it worked better without the w.close();
    – jon
    Aug 7, 2016 at 12:22
  • but when i put a php or html page, browser just print a blank page. <a href="javascript: w=window.open('http://google.com'); w.print(); w.close(); ">​​​​​​​​​​​​​​​​​print pdf</a>
    – h1h2
    Dec 1, 2020 at 21:45
7

This method works well for me.

<a href="/url/" onclick="window.open(this.href).print(); return false">
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.

0
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>
1
  • This works nicely, that it stays on the same page, opening an unseen iframe does not seem so desirable always. Mar 1, 2017 at 16:28
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.

:)

1
  • 1
    Actually this prints the page instead of the PDF file Feb 20, 2019 at 14:06
-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

6
  • Thanks for quick response.I just want to know open in new tab with PRINT DIALOG.
    – Sandy
    Sep 5, 2012 at 8:23
  • do you want to keep the PRINT text on the new tab or previous tab?
    – Sujanth
    Sep 5, 2012 at 8:40
  • do not want to keep this text in new tab only print dialog.
    – Sandy
    Sep 5, 2012 at 8: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 5, 2012 at 9: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: fpdf.org/en/script/script36.php
    – Sujanth
    Sep 5, 2012 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.