Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2003
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onbeforeprint handler

    How would I use the onbeforeprint handler to dynamically populate the link tag to print the correct .txt file(href="printerfriendly.txt") from a called JS function?"

    I forgot to mention what a link tag is for those who are not sure:

    <link rel="alternate" media="print" href="printerfriendly.txt">

    the printerfriendly.txt needs to be populated with
    start.txt when the start function is involked, simularily
    text1.txt when text1 function is involked;
    page2.txt with page2 function; AND
    ender.txt with ender function

    hope this makes sense!


    hmm... I'm lost making the association between the JS functions (that are going to be called) to set the href of the link tag?

    <head>

    <link rel="alternate" media="print" href="printerfriendly.txt">

    <script language="JavaScript"><!--
    function text1(){


    }
    function text2(){


    }
    function text3(){


    }
    // --></script>
    </head>

    <body onbeforeprint="text1();text2();text3();">

    Actual page here

    </body>

  • #2
    Regular Coder
    Join Date
    Mar 2003
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've played around with it and this is what I came up with, which doen't work, please help.

    <head>

    <script language="JavaScript"><!--
    function text1(){
    document.writeln("<link rel="alternate" media="print" href="text1.txt">");
    }
    function text2(){
    document.writeln("<link rel="alternate" media="print" href="text2.txt">");
    }
    function text3(){
    document.writeln("<link rel="alternate" media="print" href="text3.txt">");
    }
    // --></script>
    </head>

    <body onbeforeprint="text1();text2();text3();">

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    Sweden
    Posts
    66
    Thanks
    1
    Thanked 0 Times in 0 Posts
    A note:

    You can't have the same type of tag without using \ before it.

    Ie.

    document.writeln('<link rel="alternate" media="print" href="text1.txt">');

    or

    document.writeln("<link rel=\"alternate\" media=\"print\" href=\"text1.txt\">");


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •