www.webdeveloper.com
Results 1 to 6 of 6

Thread: print external html file without opening it

  1. #1
    Join Date
    Oct 2004
    Posts
    11

    print external html file without opening it

    hi everybody!!
    I just found a useful code to print an external html file with no need of opening it...
    it works fine as long as the button is in a html page with no frame, but I need to use it in a frameset.
    so: this code works if I open directly the bar-file and click on the print button, but when I open the whole html file (text + bar) it will print the bar-page.
    I tried adding the "head" code in the main file too, but this way it would lose the "href" and try to print a "something" file...
    what I seem to understand is that somehow I should change a path and/or a variable in the function in order to make it work..but I really don't know what... thanks for your help!!

    this is the code:

    HTML Code:
    [HEAD]
    [link id="prt" name="prt" rel=alternate media=print href="something"/]
    [script]
    function printWindow(){
     bV = parseInt(navigator.appVersion)
     if (bV >= 4) window.print()
    }
    function setPrintedPage(altdoc) {
    var prt;
    var prt = document.getElementsByTagName("link")[0];
    prt.setAttribute("href", altdoc);
    printWindow();
    }
    [/script]
    [/HEAD]
     
    [BODY]
    [img src="print.gif" onClick="setPrintedPage('document1.htm');"> 
    [/BODY]

  2. #2
    Join Date
    Oct 2004
    Posts
    11
    is it so difficult??
    I was expecting a reply in 10 minutes...
    I know many of you out there can solve this question, I'll be waiting...
    thanks!!

  3. #3
    Join Date
    Sep 2004
    Location
    Midwest
    Posts
    1,629
    Your arrogant sense of entitlement astounds.

    I'm posting the following for the benefit of others.
    Using a frameset:

    ------------ Frameset -----------
    <HTML>
    <Head>
    <Link rel='alternate' media='print' href=null>
    <Script Language=JavaScript>

    function setPrintPage(prnThis){

    prnDoc = document.getElementsByTagName('Link');
    prnDoc[0].setAttribute('href', prnThis);
    window.print();
    }

    </Script>
    </Head>
    <frameset rows="80,*" frameborder="yes" border="1" framespacing="0">
    <frame name="topFrame" scrolling="yes" src="Top.html" >
    <frame name="bottomFrame" scrolling="yes" src="Bottom.html">
    </frameset>
    </HTML>

    ----------- Top.html & Bottom.html ------------
    <HTML>
    <Body>
    Click to print Test.hmtl
    <img src="print.gif" onClick="parent.setPrintPage('Test.html')">
    </Body>
    </HTML>


    -----------------

    ----------- Not using a Frameset -------------

    <HTML>
    <Head>
    <Link rel='alternate' media='print' href=null>
    <Script Language=JavaScript>

    function setPrintPage(prnThis){

    prnDoc = document.getElementsByTagName('link');
    prnDoc[0].setAttribute('href', prnThis);
    window.print();
    }

    </Script>
    </Head>
    <Body>
    Click to Print Test.html
    <img src="print.gif" onClick="setPrintPage('Test.html');">
    </Body>
    </HTML>
    Last edited by Warren86; 12-30-2004 at 07:23 AM.

  4. #4
    Join Date
    Oct 2004
    Posts
    11
    uh uh! time for making apologies...
    hi warren, I beg your pardon for my lack of netiquette...
    would you please consider English is not my mother tongue... actually I had to take my dictionary to catch the meaning of your first line.
    You see... I was only trying to "push" and provoke some reaction, I apologize for sounding arrogant.
    anyway, thank you very much...the script is simply perfect!! and quite "didactic" too... now I know about the "parent" path issue...
    thanks again!!

    by the way, what does KMA mean??

  5. #5
    Join Date
    Mar 2007
    Posts
    2

    Question

    i have used the code for printing php page.passing the php values works fine but how to pass the html form values.i m not getting the html form values plz help me
    this is my code

    <img src="print.gif" onClick="setPrintPage('print_inv1.php?order_of=<? echo $order_of; ?>&cust_type=<? echo $cust_type; ?>&cust_name=<? echo $cust_name; ?>&paymentmode=document.form10.paymentmode.value&remarks=document.form10.remarks.value');">

    i m getting the php values passed to print_inv1.php page m fails to get form values...PLZ HELP..Thnaks in advance

    Quote Originally Posted by Warren86
    Your arrogant sense of entitlement astounds.

    I'm posting the following for the benefit of others.
    Using a frameset:

    ------------ Frameset -----------
    <HTML>
    <Head>
    <Link rel='alternate' media='print' href=null>
    <Script Language=JavaScript>

    function setPrintPage(prnThis){

    prnDoc = document.getElementsByTagName('Link');
    prnDoc[0].setAttribute('href', prnThis);
    window.print();
    }

    </Script>
    </Head>
    <frameset rows="80,*" frameborder="yes" border="1" framespacing="0">
    <frame name="topFrame" scrolling="yes" src="Top.html" >
    <frame name="bottomFrame" scrolling="yes" src="Bottom.html">
    </frameset>
    </HTML>

    ----------- Top.html & Bottom.html ------------
    <HTML>
    <Body>
    Click to print Test.hmtl
    <img src="print.gif" onClick="parent.setPrintPage('Test.html')">
    </Body>
    </HTML>


    -----------------

    ----------- Not using a Frameset -------------

    <HTML>
    <Head>
    <Link rel='alternate' media='print' href=null>
    <Script Language=JavaScript>

    function setPrintPage(prnThis){

    prnDoc = document.getElementsByTagName('link');
    prnDoc[0].setAttribute('href', prnThis);
    window.print();
    }

    </Script>
    </Head>
    <Body>
    Click to Print Test.html
    <img src="print.gif" onClick="setPrintPage('Test.html');">
    </Body>
    </HTML>

  6. #6
    Join Date
    May 2008
    Posts
    1
    This does not work:

    <HTML>
    <HEAD>
    <link id="prt" name="prt" rel=alternate media=print href="something"/>
    <script>
    function printWindow(){
    bV = parseInt(navigator.appVersion)
    if (bV >= 4) window.print()
    }
    function setPrintedPage(altdoc) {
    var prt;
    var prt = document.getElementsByTagName("link")[0];
    prt.setAttribute("href", altdoc);
    printWindow();
    }
    </script>
    </HEAD>

    <BODY>
    <img src="print.gif" onClick="setPrintedPage('document1.htm');">
    </BODY>
    </HTML>

    It only prints the actual page the link image is on. I have inserted 10 different URLs in replace of 'document1.htm' and none of them printed. Only this page gets printed.

    Any other options?

Thread Information

Users Browsing this Thread

There are currently 3 users browsing this thread. (0 members and 3 guests)

Posting Permissions

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



Recent Articles