469,353 Members | 2,265 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

catch print event with client-side javascript?

mp
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

Jul 23 '05 #1
17 12086
VK
did you look at onBeforePrint event? i'm not sure if it isn't IE specific
though.
Jul 23 '05 #2
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]
Jul 23 '05 #3
VK
> > 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?
Jul 23 '05 #4
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
Jul 23 '05 #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 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
Jul 23 '05 #6
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.
Jul 23 '05 #7
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.
Jul 23 '05 #8
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
Jul 23 '05 #9
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.
Jul 23 '05 #10
On Sun, 10 Oct 2004 20:53:46 +0200, Thomas 'PointedEars' Lahn
<Po*********@web.de> 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.
Jul 23 '05 #11
On Sun, 10 Oct 2004 20:53:46 +0200, Thomas 'PointedEars' Lahn
<Po*********@web.de> 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.
Jul 23 '05 #12
Jim Ley 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,


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.)


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


[...]
Equally, the W3C have stated that HTML 4.01 is the last HTML, and
XHTML 1.0 the last thing servable as text/html


Everything is servable as text/html, that does not mean it makes sense to do
so. Since XHTML SHORTTAG and HTML SHORTTAG differ and it is highly likely
that a tagsoup parser will be used to parse that XHTML as broken HTML, it
does not make sense to serve XHTML as text/html.
- so future proof is meaningless in text/html document content terms.


No, it is not. Because of the above, XHTML has failed to become a viable
alternative to HTML either, it can only serve as a supplement for compliant
UAs or on intranet sites with a defined UA environment.
X-Post & F'up2 comp.infosystems.www.authoring.html

PointedEars
--
And on the 8th day He said, OK Murphy, you take over.
Jul 23 '05 #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.
Jul 23 '05 #14
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?
Jul 23 '05 #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!
Jul 23 '05 #16
On 21 Oct 2004 00:18:20 GMT, martin froment <fr*****@hotmail.com>
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=onbe...+site%3Aw3.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.
Jul 23 '05 #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!
Jul 23 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sveta | last post: by
reply views Thread by Phuff | last post: by
5 posts views Thread by Tom Louchbaum | last post: by
2 posts views Thread by D. Alvarado | last post: by
reply views Thread by Benny Chow | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.