print target javascript

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

    Expert Comment

    by:Michel Plungjan
    Huh? What is a print_target?

    Author Comment

    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
    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" */
    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]



    Author Comment

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

    LVL 75

    Accepted Solution


    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

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

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Both jQuery and Mootools offer some nice, easy to use scripts. Mootools is best known for their interactive slideshows and jQuery for their menus, but both have many other uses as well.   jQuery is basically a toolkit with many DOM (http://en.wik…
    In my daily work (mainly using, 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 …
    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…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now