Link to home
Start Free TrialLog in
Avatar of mambo5
mambo5

asked on

a print button...

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
Avatar of DirkVe
DirkVe

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>


Avatar of Paul Maker
<A HREF="Javascript:document.print();">Print Frame</A>

put this in each frame you want to print
Avatar of mambo5

ASKER

hi guys,

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

thanks for the code..

mambo5
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
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).
DirkVe :) I am not aware about it not working in IE 4. Thanks a lot.

hongjun
ASKER CERTIFIED SOLUTION
Avatar of Paul Maker
Paul Maker
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Small correction:

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

instead of

if (bV >= 4) window.print();
cheers
I like this type of friendly exchanges :)

hongjun
Avatar of mambo5

ASKER

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
Avatar of mambo5

ASKER

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..
So, your problem solved?

hongjun
Avatar of mambo5

ASKER

yup..yup...thanks..thanks..
ahh who gets the points