Print button (or link) invisible to printer

Posted on 2000-03-20
Medium Priority
Last Modified: 2008-02-26
I need to open a new window with no toolbar. But, I need to provide print functionality.  I've tried this solution:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=10017405 &search=

The print button appears to be replaced, then the print dialogue box appears. However, when the page is printed the print button image is still there. Also, after the page is printed the print button image does not reappear in the browser window. Does anyone know why? Or does anyone know any other way of providing a print button that will not show on the printed report?

Any help would be greatly appreciated!!

Here's my code:

onePixel = new Image()
printImage = new Image()
onePixel.src = "/home/images/email_off.jpg"    // This is a blank image
printImage.src = "/home/images/printImage2.gif"

function printPage(){

<TD WIDTH="100%" ALIGN="center"><A HREF="#" onclick="document.printButton.src=onePixel.src;Javascript: printPage()"{><IMG SRC="/home/images/printImage2.jpg" HEIGHT="25" WIDTH="50" BORDER="none" NAME="printButton" alt="Print Page"></A></TD>
Question by:LisaWi
  • 4
  • 4

Expert Comment

ID: 2637384
instead of flipping the image, try just changing the visibility of the image..

to hide the image..

document.printButton.style.visibility = "hidden";

to show it:

document.printButton.style.visibility = "visible";


How about putting the report and print button into different frames, and calling the print() method of the sibling frame?



Author Comment

ID: 2637455
Thanks, Brian. I tried it and it didn't work. I get "document.printButton.style has no properties."

I'm kind of a newbie to HTML and Javascript. Is there something else I need to do to use the "visibility" attribute?

Expert Comment

ID: 2637552
You're using Netscape... my mistake.

add this at the end of your <body> (just before the </body> tag.)

<script language="javascript"> <!--
var isIE = (document.all)?true.false;
var objStyle = document.images["printButton"];
if(isIE) {
 objStyle = objStyle.style;

function printPage() {
  objStyle.visibility = (isIE)?"hidden":"hide";
  objStyle.visibility = (isIE)?"visible":"show";



However.. I think my second 'solution' is cleaner.

The window you open without the toolbar would be a frameset.

<frameset rows="40,*">
 <frame name="btn" src="printbutton.html">
 <frame name="report" src="report.html">

the printbutton.html would look something like this:
  <form name="f1">
   <input type="button" value="Print Report" onclick="parent.report.print();">

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 2638413
Thanks for the clarification. However, I still wasn't able to get it to work. It could very well be due to my inexperience...

I've actually already tried the frames method, and it works well for one of my reports. I'm having trouble with the other ones, though. They are invoked using a variable for the URL:

function PatRecordReportWindow() {
patRecWindow = window.open(sPatRecordReportURL', "PatRecReport",
'scrollbars=yes, width=100, height=100')

"sPatRecordReportURL" gets it's value from a cookie. I can't figure out how to pass this value to my Frameset. Any thoughts?

Expert Comment

ID: 2640705
Create a frameset for each report. You can use the same button code.

ie.. for report A, you call reportaframe.html, a frameset containing printbutton.html and reporta.html

for report B, you call reportbframe.html, a frameset containing printbutton.html and reportb.html

Just make sure the frame name for the bottom frame stays as 'report'.


Author Comment

ID: 2640889
I understand that I need a unique frameset for each report. What I don't understand is how to get my variable value for "report B" into my frameset so that it knows which page to display.

The page which calls the report gets a cookie value to determine if the user is authorized to view the report. It not, an error page is displayed. Otherwise, they get the report. (See my code snippet in my previous comment.) How do I pass the variable value to the frameset?

Thanks for your time!

Accepted Solution

brigmar earned 300 total points
ID: 2640988
If I'm following this correctly:

When you select a report from a page, the page will examine a cookie for authorisation. This authorisation takes the form of a URL which either points to the actual report or to an error page. You want to pass this URL into the frameset?

Is this correct ?

I have a feeling this is insecure. A user without authorisation need only look at the source of the authorising page to determine what the successful URL would be, and hence run the report. I would say that the authorisation should take place on the server-side before anything is written to the browser.
ie. The client requests the report. The server checks for authorisation and returns a report or an authentication failure page.


Author Comment

ID: 2641058
Thanks, Brian. You've given me several answers to my question which are all perfectly good, they just don't seem to work for my particular situation. However, I now feel I can talk a bit more intelligently to the "gurus" here at my company about the issues I'm having with this assignment.

Thanks again for your time!
-Lisa W.

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question