Solved

a print button...

Posted on 2001-07-12
16
165 Views
Last Modified: 2012-05-04
hi experts,

i need a code, on a print function. this is where i've a link, and when i click the link, it will the print that page. however, i need this link to function in a particular frame. for instance, i've 3 frames in my interface. i put a print hyperlink in one of the frame, and when the user click 'print', it will only print all the things in that frame, not the whole interface.

can this be done?

pls show me the code...thank you very much.

mambo5
0
Comment
Question by:mambo5
  • 5
  • 4
  • 4
  • +1
16 Comments
 
LVL 2

Expert Comment

by:DirkVe
Comment Utility
If you put the link in the same page as you want to print, you can use the following:

In case you want a BUTTON:
<BUTTON name="print" onCLick="window.print()">Print</BUTTON>

In case you want a LINK:
<A href="" OnClick="window.print();return false;" >Print</A>


0
 
LVL 10

Expert Comment

by:makerp
Comment Utility
<A HREF="Javascript:document.print();">Print Frame</A>

put this in each frame you want to print
0
 

Author Comment

by:mambo5
Comment Utility
hi guys,

i'll try it out and be back later...

thanks for the code..

mambo5
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
If I did not forget, window.print() does not work for Netscape. I might be wrong. I do not have Netscape to test on it now.

<script language="JavaScript">
<!--
function print_doc()
{
    if ( document.all )
        document.print();
    else if ( document.layers )
    {
        alert("Use the Print option from the menu");
    }
}
//-->
</script>


<A onClick="print_doc();" style="cursor:hand">Print Frame</A>


hongjun
0
 
LVL 2

Expert Comment

by:DirkVe
Comment Utility
window.print doesn't work in IE4 either. So this must be tested also in the function from hongjun.

Don't know for Netscape, but I thought it worked in the latest Netscape version but not in others.

A good alternative (Instead of showing an error message, like the function written by hongjun) is not to show the print-button/link if it doesn't work on your browser. So:
-Check the browser and version and show the print if it is IE5 or the latest Netscape (test it on Netscape first then).
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
DirkVe :) I am not aware about it not working in IE 4. Thanks a lot.

hongjun
0
 
LVL 10

Accepted Solution

by:
makerp earned 40 total points
Comment Utility
<SCRIPT LANGUAGE="JavaScript">

function printWindow() {
bV = parseInt(navigator.appVersion);
if (bV >= 4) window.print();
}
</script>

<a href="javascript:printWindow()">Print This Page</a>

maybe this will help
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
makerp,
Alright man!!!
He is checking for IE version :)

Just an enhancement and no offence to makerp.
<SCRIPT LANGUAGE="JavaScript">
<!--
function printWindow() {
    bV = parseInt(navigator.appVersion);
    if (bV >= 4)
        window.print();
    else
        alert("Please use the print option from the menu");
}
//-->
</script>

<a href="javascript:printWindow()">Print This Page</a>

Credit to makerp.

hongjun
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 2

Expert Comment

by:DirkVe
Comment Utility
Small correction:

if (bV > 4) window.print();

instead of

if (bV >= 4) window.print();
0
 
LVL 10

Expert Comment

by:makerp
Comment Utility
cheers
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
I like this type of friendly exchanges :)

hongjun
0
 

Author Comment

by:mambo5
Comment Utility
hi experts,

i was glad to see you guys, exchanging friendly ideas..ehehe...

thanks for all your codes. now i've the trouble dividing the points...ehehe..

all of you are really good and great..

anyway, i'll try those codes in different version of browser...

b back later...

thanks..

mambo5
0
 

Author Comment

by:mambo5
Comment Utility
hi guys, i've tried all your codes, on IE 5.5 and netscape 4.7!

you know, it's really disappointing to view my program, all out of order in netscape.

however, the print function code created makerp and modified by hongjun, works well in IE and netscape.

dirkve, thanks for your comments on how to create a button and a link in your first post. but dirkve, i've tried your last posted method,

use this

if (bV > 4) window.print();

instead of

if (bV >= 4) window.print();

****dirkve, i'm using IE 5.5, but it came out the alert message instead if i use if (bV >= 4) window.print(); !

anyway, thanks for all your codes...thanks..
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
So, your problem solved?

hongjun
0
 

Author Comment

by:mambo5
Comment Utility
yup..yup...thanks..thanks..
0
 
LVL 10

Expert Comment

by:makerp
Comment Utility
ahh who gets the points
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ODBC connection string for ODBC 6.01 24 65
Classic ASP migration directions 7 57
asp syntax 3 20
Error viewing ASP page 12 71
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

9 Experts available now in Live!

Get 1:1 Help Now