Jump to content

Print an external document using javascript onClick inside link tag


boo_lolly

Recommended Posts

Hey guys. As the topic describes, I'm trying to use the javascript onClick tool to print an external file, not the current (or any other) HTML page. I'm wondering if I can do this without having to write a custom javascript function. If so, I imagine it wouldn't be too difficult. Like writing a function that takes the path-to-file as a parameter, and then when using it it would look something like

 

<a href="#" onClick="printdocument('http://mydomain.com/docs/file.pdf');">print file</a>

 

However, I'm not sure if javascript already has a built-in function for this. Maybe something like

 

<a href="#" onClick="document.location('http://mydomain.com/docs/file.pdf').print();">print file</a>

 

Can anyone help me with this?

 

I don't know if this works with PDF files, but give it a try.

 

Add this to the top.

<link rel="alternate" media="print" href="file.pdf">

 

Then change the anchor to

<a href="file.pdf" onclick="window.print(); return false;">Print File</a>

I did something like that before and it works, yeah, but ontop of printing the file, it also assumes you want to download it, or view it in your web-browser... whichever the browser settings may be, it performs an extra operation, which I'm looking to avoid.

 

could I add a hidden iFrame embedded in the page? and have a link to print whatever is inside the frame?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.