Link to home
Start Free TrialLog in
Avatar of fox_statton
fox_statton

asked on

print target javascript

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?
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Huh? What is a print_target?
Avatar of fox_statton
fox_statton

ASKER

Sorry,
You know in IE when your right click on a link it gives you the option to print target
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">

<html>
<head>
      <title>print using link rel=alternate</title>
<link rel="alternate" href="test1.txt" media="print">
<script>
/* 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;
   window.print();
   return false;
}

</script>
</head>

<body>
<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>
<script>
   t="";
   for (i in obj[0]) t+= '\n'+i+':'+obj[0][i]
   document.getElementById('msgDiv').innerHTML='<pre>'+t+'</pre>'

</script>
</body>
</html>


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


Thanks
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yup, I was trying it with files on a webserver (but the html page was on my local machine)