print commands with javascript

  • Thread starter Henriette van de Haar
  • Start date
H

Henriette van de Haar

Hi all,

are there any javascipt commands to have a file printed that is not
presently shown in any browser window, e.g. a pdf file or a htm page?

Best Regards,
Henriette van de Haar, Hamburg/Germany
 
S

SAM

Le 6/14/09 3:34 PM, Henriette van de Haar a écrit :
Hi all,

are there any javascipt commands to have a file printed that is not
presently shown in any browser window, e.g. a pdf file or a htm page?

No.

JS can't do nothing with any file no yet loaded.
(JS can do nothing with the computer)

In the Finder, I'm not sure I can print a pdf without to open it before.
(hasn't the file to be opened/loaded before to print it ?)
 
H

Henriette van de Haar

hi Sam,

actually I now have a different problem.
With print() I print the current html-page.
However, on this page, there are some images, which I do not wish to be
printed. So I make them invisible with javascript.
Then I give the print command.
And then i make these images visible again. But too early!
Is there any eventhandler or something with which i can find out, that
the print command was succesfull and i can only then make my images
visible again?

Best Regards,
Henriette
 
M

Martin Honnen

Henriette said:
actually I now have a different problem.
With print() I print the current html-page.
However, on this page, there are some images, which I do not wish to be
printed. So I make them invisible with javascript.
Then I give the print command.
And then i make these images visible again. But too early!
Is there any eventhandler or something with which i can find out, that
the print command was succesfull and i can only then make my images
visible again?

I think IE has onbeforeprint and onafterprint events respectively allows
these event handlers but you should simply define a print stylesheet
that ensures the images are not displayed e.g.

<style type="text/css" media="print">
#imageId1, #imageId2 { display: none; }
</style>

Could of course also be done in an external stylesheet e.g.
<link rel="stylesheet" type="text/css" media="print" href="print.css"/>
 
S

SAM

Le 6/14/09 5:56 PM, Henriette van de Haar a écrit :
hi Sam,

actually I now have a different problem.
With print() I print the current html-page.
However, on this page, there are some images, which I do not wish to be
printed.

So you made the correct CCS for that, no ?

<style type="text/css" media="print">
body, h1, h2, h3, div, p, span {
color: #000; background: #fff; background-image: none; }
img { visibility: hidden }
</style>
</head>
<body>
 
S

SAM

Le 6/14/09 6:20 PM, Martin Honnen a écrit :
I think IE has onbeforeprint and onafterprint events respectively allows
these event handlers but you should simply define a print stylesheet
that ensures the images are not displayed e.g.

<style type="text/css" media="print">
#imageId1, #imageId2 { display: none; }
</style>

Could of course also be done in an external stylesheet e.g.
<link rel="stylesheet" type="text/css" media="print" href="print.css"/>


and/or also in the general styles-sheet

<style type="text/css">
body { color: red; }
@media print {
body { color: black; }
}
</style>
 
M

Michael J. Ryan

actually I now have a different problem.
With print() I print the current html-page.
However, on this page, there are some images, which I do not wish to be
printed. So I make them invisible with javascript.
Then I give the print command.
And then i make these images visible again. But too early!
Is there any eventhandler or something with which i can find out, that
the print command was succesfull and i can only then make my images
visible again?

Add a stylesheet with a media="print" attribute, included after any other
stylesheets... in this stylesheet have a ...

.noprint { display:none; }

then for any divs/content you want hidden for print, add a class="noprint"
attribute. if you already have a classname, you can space delimit them
class="something noprint"

Not a JS based answer, but probably a better solution.
 
H

Henriette van de Haar

Hi all,

thank you all for all your help. I would never have figured it out by
myself.
Now I sure know how to handle printing :).

Best regards,
Henriette
 
J

Jeff North

| hi Sam,
|
| actually I now have a different problem.
| With print() I print the current html-page.
| However, on this page, there are some images, which I do not wish to be
| printed. So I make them invisible with javascript.
| Then I give the print command.
| And then i make these images visible again. But too early!
| Is there any eventhandler or something with which i can find out, that
| the print command was succesfull and i can only then make my images
| visible again?
|
| Best Regards,
| Henriette

It is easier to do this in CSS.

On your page add class="NoPrint" to all the items that you don't want
to print.

Create a new css file (print.css) with the entry:
..NoPrint { display: none; }

On you html page add the stylesheet with
<link href="print.css" rel="stylesheet" type="text/css" media="print">

This will not work if CSS is turned off but the same problem exists if
javascript is disabled with your current set up.
 
H

Henriette van de Haar

Jeff said:
It is easier to do this in CSS.

On your page add class="NoPrint" to all the items that you don't want
to print.

Create a new css file (print.css) with the entry:
.NoPrint { display: none; }

On you html page add the stylesheet with
<link href="print.css" rel="stylesheet" type="text/css" media="print">

Hi Jeff,
this seems to be the easiest solution to my problem. Thanks!

This will not work if CSS is turned off but the same problem exists if
javascript is disabled with your current set up.

Yes. Mostly I try to avoid javascript.

Best Regards,
Henriette
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top