print target javascript

Posted on 2006-05-16
Medium Priority
Last Modified: 2008-02-01
Is there anyway to access the print target function from IE (eg print_target("http://www.x.com/file.doc") for example so that when a user clicks on an item they are offered the ability to print it?
Question by:fox_statton
  • 3
  • 3
LVL 75

Expert Comment

by:Michel Plungjan
ID: 16688629
Huh? What is a print_target?

Author Comment

ID: 16688839
You know in IE when your right click on a link it gives you the option to print target
LVL 75

Expert Comment

by:Michel Plungjan
ID: 16688912
Yeeees? And when do you want to access that, how and why?

Do you mean this?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

      <title>print using link rel=alternate</title>
<link rel="alternate" href="test1.txt" media="print">
/* Print alternate prints using link
   Copyright (c) 2003-2006 Michel Plungjan "javascripts at planet.nl" */
obj = document.getElementsByTagName('LINK');  
function changePrint(url) {
   if (url) obj[0].href=url;
   return false;


<a href="test1.txt"
onClick="return changePrint('test1.txt')">print test1.txt</a><br>

<a href="test2.html"
onClick="return changePrint('test2.html')">print test2.html</a>

<div id="msgDiv"></div>
   for (i in obj[0]) t+= '\n'+i+':'+obj[0][i]


Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 16689159
Yes that seems to work with normal files (like html pages etc), but it doesnt work with PDFs, any ideas?

LVL 75

Accepted Solution

Michel Plungjan earned 2000 total points
ID: 16689462

PDF is a tricky thing. It SHOULD work, but it seems IE does not hand over the print to acrobat.

Did you try it with the files online, because there is also the matter of the headers being sent

Author Comment

ID: 16690342
yup, I was trying it with files on a webserver (but the html page was on my local machine)

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question