#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13

    printing with javascript


    can someone point me in the direction of some decent documentation of how to print a file with javascript from a browser?

    Any help is appreciated.
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    24
    No one replying? Possibly because there's no real documentation

    Start by trying:

    window.print()

    If you're printing a different frame then IE needs to set the focus first:

    var isIE = null
    if (navigator.appVersion.indexOf("MSIE") != -1) {
    isIE = true
    }
    if (isIE) {
    parent.frame.focus()
    this.print()
    } else {
    parent.frame.print()
    }


    Don't know about any lesser browsers such as NS4 though!

    Oh yeah, and before adios berates me once again for saying window.something when the window. isn't needed, I just do things that way okay?!

    So you can use print()

    instead of window.print()
    Last edited by binky; November 15th, 2001 at 10:34 AM.
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    24
    Oh, and added to all that. If you're printing anything other than the web page it doesn't work. You can't print any old file from the users filesystem because that would be dangerous. If it's something that is pretty secure and being used by people you know then you could get them to download an HTA version or a Java method of doing it. But really it's not worth the effort.

    May be that's not what you're after but I'm just suggestin'!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Boston
    Posts
    261
    Rep Power
    13
    actually that's exactly what I was looking for... you see I'm trying to escape having to print from the browser window becuase the browsers impose all sorts of whacky formatting. I need to be able to print data retrieved from a database onto a page in very specific locations. So I am trying to figure out how to initiate a print command to print a generated text file that would reside on the server.
  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    24
    What you could do is format it all nicely (but no need if it's just a text file). Then have PHP or ASP load the text file into a very simplistic web page and print that using the print option of the browser.

    Banks such as Smile (I've noticed) give the option to ask for print formatting on a page when printing. This opens a new window with a neat version.

    It's possible to do a media option in CSS that allows for different CSS properties for screen and print display. So you can hide things when a page is printed out without having to do any changes on screen. (This is something I have been planning on getting around to, eventually).

IMN logo majestic logo threadwatch logo seochat tools logo