catch print event with client-side javascript?

M

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
 
T

Thomas 'PointedEars' Lahn

VK said:
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
 
V

VK

did you look at onBeforePrint event? i'm not sure if it isn't IE
specific
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?
 
T

Thomas 'PointedEars' Lahn

VK said:
^^
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.
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
 
T

Thomas 'PointedEars' Lahn

VK said:
^^
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.
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
 
R

Richard Cornford

Thomas said:
VK wrote:

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

Thomas 'PointedEars' Lahn

Richard said:
<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
 
R

Randy Webb

Thomas said:
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.
 
R

Richard Cornford

Thomas said:
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.
 
J

Jim Ley

Richard said:
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.
 
M

Michael Winter

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

[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.
 
T

Thomas 'PointedEars' Lahn

Richard said:
Thomas said:
Richard said:
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
 
R

Randy Webb

Thomas said:
Richard Cornford wrote:

Thomas said:
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?
 
M

martin froment

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

Jim Ley

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

martin froment

My error... I will search further next time before posting. My sources
was invalid...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top