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?

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.