catch print event with client-side javascript?

Discussion in 'Javascript' started by mp, Sep 24, 2004.

  1. mp

    mp Guest

    Hi.

    I know I can use "window.print()" to print a page, but is there a way to
    catch a print event when someone prints a document from the browser?

    Thanks.

    mp
    mp, Sep 24, 2004
    #1
    1. Advertising

  2. mp

    VK Guest

    did you look at onBeforePrint event? i'm not sure if it isn't IE specific
    though.
    VK, Sep 24, 2004
    #2
    1. Advertising

  3. VK wrote:

    > did you look at onBeforePrint event? i'm not sure if it isn't IE specific
    > though.


    It *is* IE specific and therefore not to be recommended on the global Web.


    PointedEars
    --
    For some reason, reading right through the entire quip list seemed a helluva
    lot more attractive than doing some FoxPro development... Can't imagine
    why! [www.rubberturnip.org.uk]
    Thomas 'PointedEars' Lahn, Oct 10, 2004
    #3
  4. mp

    VK Guest

    > > did you look at onBeforePrint event? i'm not sure if it isn't IE
    specific
    > > though.

    >
    > It *is* IE specific and therefore not to be recommended on the global Web.


    IMHO it's totally OK to mention browser-specific methods and property, as
    long as you mark it in your posting (IE only, may not work in X, etc)

    Sometimes you just cannot reach the same result in the same way on different
    browsers. Then you have to "clue" together several solutions.

    In this case: is there any specific workaround for Mozilla-based browsers?
    VK, Oct 10, 2004
    #4
  5. VK wrote:

    >> > did you look at onBeforePrint event? i'm not sure if it isn't IE

    > specific

    ^^
    Please read <http://insideoe.tomsterdam.com/> to get informed about the bugs
    in the software you are using and how to work around them. Broken quoting
    is inappropriate.

    >> > though.

    >>
    >> It *is* IE specific and therefore not to be recommended on the global
    >> Web.

    >
    > IMHO it's totally OK to mention browser-specific methods and property, as
    > long as you mark it in your posting (IE only, may not work in X, etc)


    I have not stated the opposite. Of course it is OK to mention it (and
    yes, it is then required to mark it as proprietary), however it is not
    recommended to *use* it.

    > Sometimes you just cannot reach the same result in the same way on
    > different browsers. Then you have to "clue" together several solutions.


    You are missing the point.

    > In this case: is there any specific workaround for Mozilla-based browsers?


    I don't know of any, and in fact I fail to see why such thing would be
    necessary.


    PointedEars
    Thomas 'PointedEars' Lahn, Oct 10, 2004
    #5
  6. VK wrote:

    >> > did you look at onBeforePrint event? i'm not sure if it isn't IE

    > specific

    ^^
    Please read <http://insideoe.tomsterdam.com/> to get informed about the bugs
    in the software you are using and how to work around them. Broken quoting
    is inappropriate.

    >> > though.

    >>
    >> It *is* IE specific and therefore not to be recommended on the global
    >> Web.

    >
    > IMHO it's totally OK to mention browser-specific methods and property, as
    > long as you mark it in your posting (IE only, may not work in X, etc)


    I have not stated the opposite. Of course it is OK to mention it (and
    yes, it is then required to mark it as proprietary), however it is not
    recommended to *use it on the global Web*.

    > Sometimes you just cannot reach the same result in the same way on
    > different browsers. Then you have to "clue" together several solutions.


    You are missing the point.

    > In this case: is there any specific workaround for Mozilla-based browsers?


    I don't know of any, and in fact I fail to see why such thing would be
    necessary.


    PointedEars
    Thomas 'PointedEars' Lahn, Oct 10, 2004
    #6
  7. Thomas 'PointedEars' Lahn wrote:
    > VK wrote:

    <snip>
    >> IMHO it's totally OK to mention browser-specific methods and
    >> property, as long as you mark it in your posting (IE only,
    >> may not work in X, etc)

    >
    > I have not stated the opposite. Of course it is OK to mention
    > it (and yes, it is then required to mark it as proprietary),
    > however it is not recommended to *use it on the global Web*.

    <snip>

    Bullshit! It is completely appropriate to use any feature implemented by
    any browser (or number of browsers) regardless of how common its
    implementation is. If the implementation is designed as an enhancement,
    and clean degradation is facilitated in the design, then users of
    browsers that do not support any given feature are no worse off than the
    users of browsers that do not support scripting at all.

    Richard.
    Richard Cornford, Oct 10, 2004
    #7
  8. Richard Cornford wrote:

    > Thomas 'PointedEars' Lahn wrote:
    >> VK wrote:

    > <snip>
    >>> IMHO it's totally OK to mention browser-specific methods and
    >>> property, as long as you mark it in your posting (IE only,
    >>> may not work in X, etc)

    >>
    >> I have not stated the opposite. Of course it is OK to mention
    >> it (and yes, it is then required to mark it as proprietary),
    >> however it is not recommended to *use it on the global Web*.

    > <snip>
    >
    > Bullshit!


    You may call it like you want, it is nevertheless true.

    > It is completely appropriate to use any feature implemented by
    > any browser (or number of browsers) regardless of how common its
    > implementation is. [...]


    There is no standards compliant or even officially recommended
    "onbeforeprint" event handler attribute, using it creates invalid
    HTML, making the document dependent on a certain UA and vendor and
    less future-proof. So far for your "assessment".


    PointedEars
    --
    If the wind changes it will freeze like that.
    Thomas 'PointedEars' Lahn, Oct 10, 2004
    #8
  9. mp

    Randy Webb Guest

    Thomas 'PointedEars' Lahn wrote:

    > Richard Cornford wrote:
    >>Thomas 'PointedEars' Lahn wrote:
    >>>VK wrote:

    >><snip>
    >>>>IMHO it's totally OK to mention browser-specific methods and
    >>>>property, as long as you mark it in your posting (IE only,
    >>>>may not work in X, etc)
    >>>
    >>>I have not stated the opposite. Of course it is OK to mention
    >>>it (and yes, it is then required to mark it as proprietary),
    >>>however it is not recommended to *use it on the global Web*.

    >><snip>
    >>Bullshit!

    > You may call it like you want, it is nevertheless true.


    No it's not.

    >>It is completely appropriate to use any feature implemented by
    >>any browser (or number of browsers) regardless of how common its
    >>implementation is. [...]

    > There is no standards compliant or even officially recommended
    > "onbeforeprint" event handler attribute, using it creates invalid
    > HTML, making the document dependent on a certain UA and vendor and
    > less future-proof. So far for your "assessment".


    It doesn't "create invalid HTML" if done properly.

    window.onbeforeprint = myFunction;
    function myFunction(){}

    Before you babble incoherently about what "creates invalid HTML" and
    what doesn't, perhaps you should learn a little more about scripting.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Randy Webb, Oct 10, 2004
    #9
  10. Thomas 'PointedEars' Lahn wrote:
    > Richard Cornford wrote:
    >> Thomas 'PointedEars' Lahn wrote:
    >>> VK wrote:

    >> <snip>
    >>>> IMHO it's totally OK to mention browser-specific methods and
    >>>> property, as long as you mark it in your posting (IE only,
    >>>> may not work in X, etc)
    >>>
    >>> I have not stated the opposite. Of course it is OK to mention
    >>> it (and yes, it is then required to mark it as proprietary),
    >>> however it is not recommended to *use it on the global Web*.

    >> <snip>
    >>
    >> Bullshit!

    >
    > You may call it like you want, it is nevertheless true.


    If there are people recommending never using proprietary features of web
    browsers on the Internet then they are clueless half-wits, and what they
    are proposing is bullshit.

    The capabilities of any browser can be exploited to its fullest
    regardless of what those capabilities are, and so long the action of the
    script is an optional enhancement and clean degradation is facilitated
    in the script design it doesn't matter one jot if only the users of one
    version of one particular browsers get to experience the benefits.

    >> It is completely appropriate to use any feature implemented by
    >> any browser (or number of browsers) regardless of how common its
    >> implementation is. [...]

    >
    > There is no standards compliant or even officially recommended
    > "onbeforeprint" event handler attribute, using it creates invalid
    > HTML, making the document dependent on a certain UA and vendor and
    > less future-proof. So far for your "assessment".


    Not putting an invalid attribute in the HTML is no barrier to employing
    the feature through scripting.

    Richard.
    Richard Cornford, Oct 10, 2004
    #10
  11. mp

    Jim Ley Guest

    On Sun, 10 Oct 2004 20:53:46 +0200, Thomas 'PointedEars' Lahn
    <> wrote:

    >Richard Cornford wrote:
    >> It is completely appropriate to use any feature implemented by
    >> any browser (or number of browsers) regardless of how common its
    >> implementation is. [...]

    >
    >There is no standards compliant or even officially recommended
    >"onbeforeprint" event handler attribute, using it creates invalid
    >HTML,


    No, it doesn't, there's plenty of ways of making a valid version of
    HTML containing that attribute, or you could do it in the internal
    subset. It wouldn't be a W3C recommended HTML (but so what, there's
    lots of good HTML's ISO etc.)

    > making the document dependent on a certain UA and vendor and
    >less future-proof.


    Hmm, less future proof could be an argument - the existence of the
    attribute in a UA does prevent other UA's implementing, or standards
    orgs. from standardising it in a different way - but that's hardly a
    danger in using it - creating it caused the problem.

    Equally, the W3C have stated that HTML 4.01 is the last HTML, and
    XHTML 1.0 the last thing servable as text/html - so future proof is
    meaningless in text/html document content terms.

    Jim.
    Jim Ley, Oct 10, 2004
    #11
  12. On Sun, 10 Oct 2004 20:53:46 +0200, Thomas 'PointedEars' Lahn
    <> wrote:

    [snip]

    > There is no standards compliant or even officially recommended
    > "onbeforeprint" event handler attribute, using it creates invalid HTML,
    > making the document dependent on a certain UA and vendor and less
    > future-proof.


    It only makes the document depend on IE if you let it. Read Richard's post
    again (the part you removed). I believe he mentioned graceful
    degradation[1].

    > So far for your "assessment".


    "So much for your assessment", was the phrase you were looking for.

    Mike


    [1] Or words to that effect. I'm deleting this thread, including this
    recent set of posts. Richard's post is already irretrievable and Google
    won't have the text for quite a while.

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
    Michael Winter, Oct 10, 2004
    #12
  13. Richard Cornford wrote:

    > Thomas 'PointedEars' Lahn wrote:
    >> Richard Cornford wrote:
    >>> It is completely appropriate to use any feature implemented by
    >>> any browser (or number of browsers) regardless of how common its
    >>> implementation is. [...]

    >>
    >> There is no standards compliant or even officially recommended
    >> "onbeforeprint" event handler attribute, using it creates invalid
    >> HTML, making the document dependent on a certain UA and vendor and
    >> less future-proof. So far for your "assessment".

    >
    > Not putting an invalid attribute in the HTML is no barrier to employing
    > the feature through scripting.


    There is no barrier to that, true. I did not overlooked that alternative
    as you might think, I just don't find that a viable solution as well, as
    it requires one more feature test (and even this won't be enough to prevent
    script errors) and I fail to see even the necessity of it.


    PointedEars
    --
    The website you seek cannot be located, but countless more exist.
    Thomas 'PointedEars' Lahn, Oct 10, 2004
    #13
  14. mp

    Randy Webb Guest

    Thomas 'PointedEars' Lahn wrote:

    > Richard Cornford wrote:
    >
    >
    >>Thomas 'PointedEars' Lahn wrote:
    >>
    >>>Richard Cornford wrote:
    >>>
    >>>>It is completely appropriate to use any feature implemented by
    >>>>any browser (or number of browsers) regardless of how common its
    >>>>implementation is. [...]
    >>>
    >>>There is no standards compliant or even officially recommended
    >>>"onbeforeprint" event handler attribute, using it creates invalid
    >>>HTML, making the document dependent on a certain UA and vendor and
    >>>less future-proof. So far for your "assessment".

    >>
    >>Not putting an invalid attribute in the HTML is no barrier to employing
    >>the feature through scripting.

    >
    >
    > There is no barrier to that, true. I did not overlooked that alternative
    > as you might think, I just don't find that a viable solution as well, as
    > it requires one more feature test (and even this won't be enough to prevent
    > script errors) and I fail to see even the necessity of it.


    No, using window.onbeforeprint does not require "one more feature test".
    It simply sets a new attribute for the window object if the
    onbeforeprint is not supported. I tested it (unlike you) before I ever
    posted about it. It silently fails (read - no errors), in non-IE
    browsers, as it should.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Answer:It destroys the order of the conversation
    Question: Why?
    Answer: Top-Posting.
    Question: Whats the most annoying thing on Usenet?
    Randy Webb, Oct 10, 2004
    #14
  15. The event "onbeforeprint" has been defined by the W3C for HTML 4.x and
    should trigger as expected on all browser platforms which support HTML
    4.x.

    Therefore, if i have one thing to say to MS:
    Why "if(self.print)" is working well and "if(self.onbeforeprint)" isn't
    supported ?

    Martin.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    martin froment, Oct 21, 2004
    #15
  16. mp

    Jim Ley Guest

    On 21 Oct 2004 00:18:20 GMT, martin froment <>
    wrote:

    >The event "onbeforeprint" has been defined by the W3C for HTML 4.x and
    >should trigger as expected on all browser platforms which support HTML
    >4.x.


    Could you point me to the relevant part of the W3C specification?

    as
    http://www.google.com/search?&q=onbeforeprint site:w3.org

    returns no documents, suggesting as I thought onbeforeprint is an IE
    extension, as MS themselves think it is:

    | Standards Information
    |
    | There is no public standard that applies to this event.

    Now I know the HTML WG can go a little crazy sometimes, they're nice
    people, but I think they would've documented it and not just told you.

    >Therefore, if i have one thing to say to MS:
    >Why "if(self.print)" is working well and "if(self.onbeforeprint)" isn't
    >supported ?


    onbeforeprint works fine in IE.

    Jim.
    Jim Ley, Oct 21, 2004
    #16
  17. My error... I will search further next time before posting. My sources
    was invalid...

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    martin froment, Oct 21, 2004
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=
    Replies:
    2
    Views:
    6,476
    rick74
    May 27, 2008
  2. Boss302
    Replies:
    0
    Views:
    1,029
    Boss302
    Nov 21, 2006
  3. Bogdan
    Replies:
    2
    Views:
    639
    Bogdan
    Jun 9, 2008
  4. Zoe Hart
    Replies:
    1
    Views:
    356
    Scott Wisniewski
    Jan 8, 2004
  5. Guest

    Fire server side event before client side event

    Guest, Mar 17, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    579
    Ken Cox [Microsoft MVP]
    Mar 18, 2005
Loading...

Share This Page