boo_lolly Posted June 20, 2009 Share Posted June 20, 2009 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? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 22, 2009 Share Posted June 22, 2009 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> Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted June 24, 2009 Author Share Posted June 24, 2009 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.