SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Printing with Javascript

    I want to print a page when a link is clicked, so I tried using the print() function. Seems to work, but I always get that annoying dialog box that I have to click print on. Is there a way to bypass the dialog box and just print a page without bothering the user?

    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not that I've ever seen.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Evangelist Mr. Brownstone's Avatar
    Join Date
    May 2002
    Location
    Relative
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Drew630
    I want to print a page when a link is clicked, so I tried using the print() function. Seems to work, but I always get that annoying dialog box that I have to click print on. Is there a way to bypass the dialog box and just print a page without bothering the user?
    And deny them their right to choose which device or service (eg, a PDF writer) to print to?
    Of course, that's just my opinion. I could be wrong.

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Mr. Brownstone
    And deny them their right to choose which device or service (eg, a PDF writer) to print to?
    Or a networked printer? I have 2 printers networked in addition to the PDF distiller in my printer options at work. One printer is for black-and-white, where I do most of my printing, and the other is color, which I use only for high-quality stuff (i.e. Photoshop mockups).

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Long-story-short: don't assume the user wants to use their default printer.

    It's very likely that you could anger the user if their default printer is some high-dollar color dye-sublimation printer with expensive ink when they'd rather print this page to their bargain-basement laser that costs only 3/10 per page to operate.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, the issue isn't restricting where they want to print. That is a good point, so I guess it isn't a good idea to bypass this. My problem is, that I am trying to print multiple web pages by clicking on a print button. Basically, I built a webpage that displays HTML versions of Crystal reports, but when the reports are exported, each page of the report is its own HTML page. So when a user wants to print a report, it isn't a good idea for them to print each page individually.

    So what I was trying to do is have an array of the page names, and use a javascript function to change the location of a page and then print that page, then go to the next page and print, etc. Thus, it is a workaround to "cycling" through a list of files.

    Does this make any sense? Does anyone have a suggestion?

    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.

  7. #7
    SitePoint Evangelist Mr. Brownstone's Avatar
    Join Date
    May 2002
    Location
    Relative
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could always use the CSS property page-break-after: in a BR tag to seperate your pages:
    HTML Code:
    <br style="page-break-after: always;" />
    Of course, that's just my opinion. I could be wrong.

  8. #8
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried your code brownstone, but it didn't seem to work. I also tried encapsulting sections of the HTML with div tags that utilizied this, but that also did not work. I did a little reading on paged content using CSS, but I haven't found much on controling how content is printed, just in how it is displayed. Does anyone have any suggestions?

    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.

  9. #9
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Drew630
    i tried your code brownstone, but it didn't seem to work. I also tried encapsulting sections of the HTML with div tags that utilizied this, but that also did not work. I did a little reading on paged content using CSS, but I haven't found much on controling how content is printed, just in how it is displayed. Does anyone have any suggestions?

    Drew
    Make sure your stylesheet is print-media specific, like so:
    HTML Code:
    <link rel="stylesheet" type="text/css" href="/styles/print.css" media="print" />


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
  •