html javascript print command

T

tigeressal

hi,
im new to this group but ill be direct to the point.

im tryin to create a simple webpage that will print the contents of
the webpage to a printer on a client side machine.

i know the command is ' window.print() ' and that i can have it in
the ' onload() ' statement so that the print dialouge appears prior to
printing.

here my question. how do i eliminate the Header and Footer information
that is automatically generated by the webpage?(i.e. the website name
at the top, and the location url at the bottom)

any help appreciated.

regards

rak
 
J

Jonathan N. Little

tigeressal said:
hi,
im new to this group but ill be direct to the point.

im tryin to create a simple webpage that will print the contents of
the webpage to a printer on a client side machine.

i know the command is ' window.print() ' and that i can have it in
the ' onload() ' statement so that the print dialouge appears prior to
printing.

I wouldn't recommend it. Folks who browse the web expect to *see* a page
when it loads, if they want to print it they will click print from their
browser. Anyway what if they don't have a printer? Maybe they are view
the page from on of those iPhones...

here my question. how do i eliminate the Header and Footer information
that is automatically generated by the webpage?(i.e. the website name
at the top, and the location url at the bottom)

You cannot, those are user settings on the browser. You cannot script them.
 
P

PW

tigeressal said:
hi,
im new to this group but ill be direct to the point.

im tryin to create a simple webpage that will print the contents of
the webpage to a printer on a client side machine.

i know the command is ' window.print() ' and that i can have it in
the ' onload() ' statement so that the print dialouge appears prior to
printing.

here my question. how do i eliminate the Header and Footer information
that is automatically generated by the webpage?(i.e. the website name
at the top, and the location url at the bottom)

any help appreciated.

regards

rak




First, create a style like this ...
<style type="text/css">
<!--
@media print{.dontprintme{display:none;}}
-->
</style>



Next, whenever you are serving something that you don't want to be printed,
place it in a paragraph like this ...
(this is my print button by the way)
<p class="dontprintme">
<BUTTON TYPE=BUTTON onClick="window.print()"
style="width:250px;height:50px;">&nbsp&nbspPRINT&nbsp&nbsp</BUTTON>
<p>



Now, when you run the page, and you click the button, then everything thats
NOT within a 'dontprintme' paragraph will not be printed.

HTH,
PW
 
P

PW

First, create a style like this ...
<style type="text/css">
<!--
@media print{.dontprintme{display:none;}}
-->
</style>



Next, whenever you are serving something that you don't want to be
printed, place it in a paragraph like this ...
(this is my print button by the way)
<p class="dontprintme">
<BUTTON TYPE=BUTTON onClick="window.print()"
style="width:250px;height:50px;">&nbsp&nbspPRINT&nbsp&nbsp</BUTTON>
<p>



Now, when you run the page, and you click the button, then everything
thats NOT within a 'dontprintme' paragraph will not be printed.

HTH,
PW


OOPS, that should have said ...
Now, when you run the page, and you click the button, then everything thats
NOT within a 'dontprintme' paragraph WILL be printed.
 
J

Jonathan N. Little

PW said:
First, create a style like this ...
<style type="text/css">
<!--
@media print{.dontprintme{display:none;}}
-->
</style>



Next, whenever you are serving something that you don't want to be printed,
place it in a paragraph like this ...
(this is my print button by the way)
<p class="dontprintme">
<BUTTON TYPE=BUTTON onClick="window.print()"
style="width:250px;height:50px;">&nbsp&nbspPRINT&nbsp&nbsp</BUTTON>
<p>

Ah, but what OP want to excluded is not part of his web page that he
composed but the URL and date and page numbers that is added by the
browser by default. This is a user setting on the browser and is not
controllable by the web author...at least with HTML and CSS
 
T

tigeressal

snipped

snipped


Ah, but what OP want to excluded is not part of his web page that he
composed but the URL and date and page numbers that is added by the
browser by default. This is a user setting on the browser and is not
controllable by the web author...at least with HTML and CSS

--
Take care,

Jonathan
-------------------

Hi thanks for the reply, You said its not possible with HTML or CSS.
Is there a way to do it by other langauges (i.e. specifically PHP)

Just to let people know, the webpage in question will NOT be on the
internet but instead on a local nework.
The printer in question is connected to a client side computer by
usb.
AND the end user WILL want to print the page as it will be part of a
particular process.

thanks

rak
 
A

Andy Dingley

It is impossible to do via code. It's hard coded into the browser.

It's not hard-coded into the browser, it's configurable. Some browsers
may have a programming interface that exposes this, and lets you
control it. This is likely to be very browser-specific. IE certainly
does have this, although it requires COM (ad thus ActiveX). If you use
MeadCo's ScriptX control on your page, it's pretty easy.
 
J

Jonathan N. Little

Andy said:
It's not hard-coded into the browser, it's configurable. Some browsers
may have a programming interface that exposes this, and lets you
control it. This is likely to be very browser-specific. IE certainly
does have this, although it requires COM (ad thus ActiveX). If you use
MeadCo's ScriptX control on your page, it's pretty easy.

Ol' wild and woolly IE! Same business lets to do all kinds of damage.
But now with MS's attempt at securing IE won't you get a zillion warning
dialogs when you invoke such ActiveX? It would hardly be a feasible
solution. Generate PDF would be the way...some freebee PHP packages out
there, fpdf comes to mind.
 
A

Andy Dingley

But now with MS's attempt at securing IE won't you get a zillion warning
dialogs when you invoke such ActiveX? It would hardly be a feasible
solution.

No, you can get away with just setting trust up once. As an app that
_needs_ to control print sizes is probably something that the user has
a non-trivial relationship with, this might be enough.
 
T

Travis Newbury

It is impossible to do via code...

Ed, are your comment so unimportant that you don't think anyone will
want to read them after a week, or are you just selfish?
 
J

Jonathan N. Little

Neredbojias said:
Well, his name is Jonathan "Little" so maybe he's just making "small"
talk.

Hey, it wasn't me being the protocol-nazi I was just explaining what
Travis meant by is remark.
 
J

Jonathan N. Little

Ed said:
Two answers to the questions. I am selfish, and I don't know why No
X-archive was checked. This post should be archived forever; however, most
of my posts have already found their place in the anals of history. ;-)

Nope, your X-No-Archive is still set.
 
T

Toby A Inkster

tigeressal said:
Just to let people know, the webpage in question will NOT be on the
internet but instead on a local nework. The printer in question is
connected to a client side computer by usb.

If it's part of an app running on a LAN, then the solution might be to
print from the *server* not the client. That way, you ought to be able to
control the printing perfectly. (The printer can still be physically
attached the the client computer -- the server could access via CUPS or
Windows printer sharing.)

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 7 days, 14:09.]

Dr Who Goes To Pompeii
http://tobyinkster.co.uk/blog/2008/04/13/dr-who-pompeii/
 

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,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top