Solved

Print button (or link) invisible to printer

Posted on 2000-03-20
8
156 Views
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(){
 self.print()
 document.printButton.src=printImage.src
}

<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>
0
Comment
Question by:LisaWi
  • 4
  • 4
8 Comments
 
LVL 4

Expert Comment

by:brigmar
Comment Utility
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";

or..

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

e.g.
parent.report.print();
or
top.report.print();

Brian
0
 

Author Comment

by:LisaWi
Comment Utility
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?
0
 
LVL 4

Expert Comment

by:brigmar
Comment Utility
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";
  self.print();
  objStyle.visibility = (isIE)?"visible":"show";

}

//-->
</script>

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">
</frameset>

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


Brian
0
 

Author Comment

by:LisaWi
Comment Utility
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?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:brigmar
Comment Utility
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'.

Brian
0
 

Author Comment

by:LisaWi
Comment Utility
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!
-Lisa
 
0
 
LVL 4

Accepted Solution

by:
brigmar earned 100 total points
Comment Utility
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.

Brian
0
 

Author Comment

by:LisaWi
Comment Utility
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.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now