Solved

a print button...

Posted on 2001-07-12
16
167 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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 …
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

813 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

19 Experts available now in Live!

Get 1:1 Help Now