SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Stamford, CT, USA
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Print a document (not current doc)

    Hi,

    Is there any way to print an alternate document when the user clicks on a link?

    I was doing this by adding:

    Code:
    <link rel=alternate media=print href="norbertprint.html">
    in the header.

    It worked if the user clicked on File/Print.

    But now I use a javascript popup menu structure and when the user clicks on the print button in the menu it does
    Code:
    javascript:window.print()
    This seems to override the "link ..." directive and just prints the current document.

    Is there any way around this?

    I tried
    Code:
    javascript:window.print("otherdoc.html")
    but that doesn't work either.

    Thanks, Ed

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure if this can be done. One workaround could be to open the page in an IFRAME which is either behind another element or invisible, and print the contents of that.

    Just an idea though, I wouldn't know how to do it

    -Sam
    Sam Hastings

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Stamford, CT, USA
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Quote Originally Posted by Devilware.net
    I'm not sure if this can be done. One workaround could be to open the page in an IFRAME which is either behind another element or invisible, and print the contents of that.

    Just an idea though, I wouldn't know how to do it

    -Sam
    Thanks for the idea. I'm afraid I wouldn't know how to do that either. ;>)

    Ed

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sure someone will be along shortly who will be able to tell you exactly how

    -Sam
    Sam Hastings

  5. #5
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    How about opening the print page in a popup window via a link, then using this script:
    Code:
    window.onload = function () {
      window.print();
      self.close();
    }
    It will open the print version, send the document to the printer, and close the popup window.

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Stamford, CT, USA
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Quote Originally Posted by vgarcia
    How about opening the print page in a popup window via a link, then using this script:
    Code:
    window.onload = function () {
      window.print();
      self.close();
    }
    It will open the print version, send the document to the printer, and close the popup window.

    That works great! Thanks!

    Is there any way to make the window invisible?

    I've got it behind the original window, but it always seems to appear in the upper right of the screen; and if the main window doesn't cover that spot, it shows.

    Thanks, Ed

  7. #7
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Use this for your javascript to open a new window:
    Code:
    window.open("yourpage.html", "newWin", "width=0, height=0");

  8. #8
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't make the pop up "invisible", but you can move it completely out of the visitor's screen view.

    Have a look at this:

    Code:
    <Script language="JavaScript">
    function printPage(pageName)
     {
    var childWin = window.open(pageName+".html", "newWin", "width=10, height=10" );
    childWin.moveTo(-100,-100);
    childWin.print();
    childWin.close();
    this.window.focus();
    }
    </script>
     
    <a href="printPage('otherdoc');">


    (All of this code must be written in the main window's source code, of course.)

    Hopefully that can come to some use to you...

  9. #9
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might not be entirely practical though, as there would still be a button in the user's taskbar for that window.

    -Sam
    Sam Hastings

  10. #10
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Devilware.net
    This might not be entirely practical though, as there would still be a button in the user's taskbar for that window.

    -Sam
    With my script, the window would close immediately after the print command, so the visitor likely wouldn't even notice the new pop up in his task bar. But even if the visitor did notice, and closed the pop up, I doubt it would impact the script in any way differently.

  11. #11
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Devilware.net
    This might not be entirely practical though, as there would still be a button in the user's taskbar for that window.

    -Sam
    If they're on Windows maybe

  12. #12
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Stamford, CT, USA
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gregc
    You can't make the pop up "invisible", but you can move it completely out of the visitor's screen view.

    Have a look at this:

    Code:
    <Script language="JavaScript">
    function printPage(pageName)
     {
    var childWin = window.open(pageName+".html", "newWin", "width=10, height=10" );
    childWin.moveTo(-100,-100);
    childWin.print();
    childWin.close();
    this.window.focus();
    }
    </script>
     
    <a href="printPage('otherdoc');">


    (All of this code must be written in the main window's source code, of course.)

    Hopefully that can come to some use to you...

    Thanks! This worked; but I had to move the print and close functions to the other page. When in the "calling" page, for some reason, printing was inconsistent.

    I have two ways to test my pages.

    1. Since my web server is local, I can use file:///Y:/html/<my site>/<my doc> where y is mapped to the server.

    2. The "normal" way: http://<myserver>/<my doc>

    Printing worked with method 1 above but not with method two. I have no idea why.

    Anyway, by moving the print and close functions to the secondary doc, everything worked.

    Thanks, Ed

  13. #13
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Stamford, CT, USA
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    It turned out that my problem had a completely different source. Please see the thread: Printing re-direction not working

    Thanks, Ed


Bookmarks

Posting Permissions

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