javascript - don't print function.
javascript - don't print function.
Author
Discussion

BliarOut

Original Poster:

72,863 posts

269 months

Wednesday 5th April 2006
quotequote all
Now I know it can be done, but I don't know where I saw it

Does anyone know how to use javascript to prevent an image/icon displaying when a page is printed through a browser?

I want to use the same page when I view/print it, but hide the icon that I use to call the onprint function. Google isn't my friend today

Don

28,378 posts

314 months

Wednesday 5th April 2006
quotequote all
I think the principle of the thing is something like this...


<DIV id=divvie name=divvie style="display: show">
your icon etc - whatever you want to hide.
</DIV>


function hideit()
{
divvie.style = "display: none";
}

BliarOut

Original Poster:

72,863 posts

269 months

Wednesday 5th April 2006
quotequote all
I can see where that's going Don I think you've just made Google like me again

robbieduncan

1,993 posts

266 months

Wednesday 5th April 2006
quotequote all
Use some CSS not javascript.

If you use a media selector you can set display:none for printing only

@media print
{
#printbutton
{
display:none;
}
}

BliarOut

Original Poster:

72,863 posts

269 months

Wednesday 5th April 2006
quotequote all
Sounds good... But needs a little more explanation for those of us that are hard of thinking

robbieduncan

1,993 posts

266 months

Wednesday 5th April 2006
quotequote all
Well assuming you have something like this:

<a href="javascriptrint();" id="printbutton">print</a>

Then just stick the above in the stylesheet. That's it.

Don

28,378 posts

314 months

Thursday 6th April 2006
quotequote all
robbieduncan said:
Well assuming you have something like this:

<a href="javascriptrint();" id="printbutton">print</a>

Then just stick the above in the stylesheet. That's it.


Sneaky. Very good. CSS - always something new to learn...