Solved

a print button...

Posted on 2001-07-12
16
166 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Prevent site to open without the www. 9 61
Question about ASP Including Files 6 42
Questions about INCLUDE FILES 2 20
Javascript to allow login/password authorization 4 30
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

20 Experts available now in Live!

Get 1:1 Help Now