SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict
    Join Date
    Feb 2005
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detecting printing - print page, onbeforeprint, css stylesheets

    How can you detect printing?
    Im aware that it is completely impossible to detect whether something has actually rolled out of the printer, but im looking for the next best thing.

    My options
    - currently im registering when someone clicks the print button on my website.
    This is nice, but due to users testing out functionality doesn't work that well.
    So i started thinking and came to these options

    - IE only
    window.onbeforeprint - Fires just prior to the page being printed
    window.onafterprint - Fires immediately after the page to be printed out has been loaded into printer queue/cache
    Its a pitty that its ie only, but I could just multiply the number of prints to compensate for the ff users. might provide better results than the first solution.

    - Css print
    Since i use a different stylesheet to change a few thins when users print, i was thinking i might be able to use this. Is there someway i could use javascript to detect whether the print stylesheet is being used by the browser to print. Im not really sure how this works technically. Any ideas on this?



    Cheers,
    Thierry
    Last edited by lajkonik86; Mar 7, 2007 at 14:31.

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is it that you want to do "onbeforeprint"?

  3. #3
    SitePoint Addict
    Join Date
    Feb 2005
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in all cases im looking to query a php database through ajax to register the print.


    Could i put an image to display:none in my normal css.
    then in my print css put it as display:visible
    and attach a javascript function to onload to register the print?

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,595
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Step one is to install the printer into your web page where Javascript can access it. Printers that are external to the browser cannot be accessed from javascript. So digitizing the printer and embeding it into your HTML is the first step if you want Javascript to be able to access it.

    JScript can tell if the printer is being accessed via onbeforeprint and onafterprint but IE is the only browser to use JScript instead of Javascript.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JScript > FScript / MScript

  6. #6
    SitePoint Addict
    Join Date
    Feb 2005
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Step one is to install the printer into your web page where Javascript can access it. Printers that are external to the browser cannot be accessed from javascript. So digitizing the printer and embeding it into your HTML is the first step if you want Javascript to be able to access it.
    I knew someone had to just mention that :P
    Don't need the actual printer, but i should be able to see if someone is using the print command?

  7. #7
    SitePoint Addict
    Join Date
    Feb 2005
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    No solution so far but keep on trying

    Since i have not been able to find a solution so far I emailed our beloved css expert for a better understanding.

    Hi,

    Thanks for your confidence but i rarely venture into I scripting territory and although I have heard of the things you are trying to emulate I have no experience with them.

    I did have a quick look around the web and Dean Edwards mentions something here in posts 6 & 7:

    http://dean.edwards.name/weblog/2005...emulator/?full

    If anyone could do t then Dean Edwards certainly could and the moz-behaviours script enables the use of the IE htc behaviours file so I don't know if there is scope there.

    However that is really outside my "safe area of expertise" and really is a question fro the Javascript forum where you have already posted.

    I hope you have luck in finding a solution to this .

    Regards

    Paul

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,595
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    .htc files need to be installed onto each individual computer for the functionality to work. Is this for an intranet? If so then just restrict people to using browsers that handle the functionality you need. If it is for the internet then you won't get people installing the .htc files onto their computer just so you can get access to information about what they are doing with their computer.

    For pages on the internet your visitors will normally have their system configured so that you have no access to anything outside of the web page itself (unless they are running an antiquated browser that doesn't have proper security).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  9. #9
    SitePoint Addict
    Join Date
    Feb 2005
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i never used htc files before, unfortunately i was not aware of this.
    looks like i should look into a different solution cause it is for the internet.

  10. #10
    SitePoint Addict
    Join Date
    Feb 2005
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well i just learned that the print css is not downloaded until it is needed. So that would be for print-preview or printing so that sounds pretty good. Just need to find a way to check with javascript if it is being downloaded.

    Help?

  11. #11
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,777
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by felgall
    htc files need to be installed onto each individual computer for the functionality to work.
    I don't think they do otherwise none of the css hover htc files would work.

    Look at the following example in Firefox.

    http://dean.edwards.name/my/examples/moz-behaviors/

    Works fine in my firefox.

  12. #12
    SitePoint Addict
    Join Date
    Feb 2005
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I started a thread about it in mozillazine
    http://forums.mozillazine.org/viewtopic.php?p=2789624


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
  •