Solved

a print button...

Posted on 2001-07-12
16
168 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
ID: 6276278
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
ID: 6276282
<A HREF="Javascript:document.print();">Print Frame</A>

put this in each frame you want to print
0
 

Author Comment

by:mambo5
ID: 6276293
hi guys,

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

thanks for the code..

mambo5
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 33

Expert Comment

by:hongjun
ID: 6276708
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
ID: 6276752
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
ID: 6276778
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
ID: 6276803
<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
ID: 6276827
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
 
LVL 2

Expert Comment

by:DirkVe
ID: 6276833
Small correction:

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

instead of

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

Expert Comment

by:makerp
ID: 6276840
cheers
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6276849
I like this type of friendly exchanges :)

hongjun
0
 

Author Comment

by:mambo5
ID: 6277978
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
ID: 6278487
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
ID: 6279134
So, your problem solved?

hongjun
0
 

Author Comment

by:mambo5
ID: 6279547
yup..yup...thanks..thanks..
0
 
LVL 10

Expert Comment

by:makerp
ID: 6279816
ahh who gets the points
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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