Printing a target frame

P

PieOPah

I have a webpage that uses frames (yes I know, frames - previously been
flamed about that, but I do not know anything else to use since I am
clueless!!! Been asked to cobble together a site since there is a
misconception that I know what I am doing!!!)

Anyway, one of the things I have been asked to do is create a button
that will allow the user to print the contents of the main window (main
frame) without the navigation bar (header frame) being printed.

Having been looknig into this, I have found the following

============================================================
Script: Print Page From Different Frame

Functions: This simple script allows you to print the con-
tent of one frame from a link in another frame.

Browsers: All

Author: etLux
============================================================

INSTRUCTIONS:

Put the following script in the <head>...</head> section of
your page. The script belongs in the page where the print
link is located -- *not* in the page to be printed.

Step 1.

<script>
// (C) 2004 www.CodeLifter.com
// Free for all users, but leave in this header
function framePrint(whichFrame){
parent[whichFrame].focus();
parent[whichFrame].print();
}

</script>

Step 2.

To create a print link, use the following general form:

<a href="javascript:framePrint('FRAMENAME');">
CLICK TO PRINT
</a>

Change FRAMENAME to the name of the frame (you can find
that in your frameset page code) that you wish to print.

Now I have followed the instrctions as provided I have replaced
FRAMENAME with the name of my frame (main) and I have deleted from
various pages the Base= code that this script seems not to like.

My problem is, when I click my desired button (I have changed the text
link to an image), I get an "access is denied" error. There has only
been one instance when this hasn't happened and that was when I had a
blank html file loaded into the main window and this file was located
in the same directory as all my other html.

Why am I getting an access is denied error? How can I resolve it? Boss
isn't going to be happy if this button doesn't work and he isn't the
type of person to accept that I have no knowledge of how to do this!

If it helps at all, this is the code I am using in my Header frame.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<TITLE></TITLE>
<META name="AUTHOR" content="Simon Argent">
<script language="JavaScript">
<!--
function FP_preloadImgs() {//v1.0
var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
for(var i=0; i<a.length; i++) { d.FP_imgs=new Image;
d.FP_imgs.src=a; }

}

function FP_swapImg() {//v1.0
var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array();
for(n=2; n<args.length;
n+=2) { elm=FP_getObjectByID(args[n]); if(elm) {
doc.$imgSwaps[doc.$imgSwaps.length]=elm;
elm.$src=elm.src; elm.src=args[n+1]; } }

}

function FP_getObjectByID(id,o) {//v1.0
var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById)
el=o.getElementById(id);
else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el)
return el;
if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes;
if(c)
for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el)
return el; }
f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el)
return el; } }
return null;
}

// -->
</script>

<script>
// (C) 2004 www.CodeLifter.com
// Free for all users, but leave in this header
function framePrint(whichFrame){
parent[whichFrame].focus();
parent[whichFrame].print();
}

</script>

</HEAD>
<BODY bgcolor="#5CAEDD" text="#000000" alink="#0000FF" bottommargin="2"
marginwidth="2" marginheight="2"
onload="FP_preloadImgs(/*url*/'images/buttonF.gif',
/*url*/'images/button10.gif', /*url*/'images/button1E.gif',
/*url*/'images/button1F.gif')">
<DIV
style="position:absolute;left:1115px;top:47px;width:54px;height:37px;z-index:0"
align="left">
<FONT face="Arial" size="2">&nbsp;</FONT></DIV>
<IMG src="images/px_wbint_cinema4_02.gif" alt="" border="0"
style="position:absolute;left:3;top:8;z-index:1" id="Title" width="567"
height="67">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div style="position: absolute; left: 1088px; top: 68px; width: 151px;
height: 30px; z-index: 6" id="Search">
<a href="../Search.html">
<img border="0" id="img2" src="images/button1D.gif" height="30"
width="150" alt="Search" fp-style="fp-btn: Glass Capsule 1;
fp-transparent: 1" fp-title="Search"
onmouseover="FP_swapImg(1,0,/*id*/'img2',/*url*/'images/button1E.gif')"
onmouseout="FP_swapImg(0,0,/*id*/'img2',/*url*/'images/button1D.gif')"
onmousedown="FP_swapImg(1,0,/*id*/'img2',/*url*/'images/button1F.gif')"
onmouseup="FP_swapImg(0,0,/*id*/'img2',/*url*/'images/button1E.gif')"></a></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div style="position: absolute; left: 1088px; top: 33px; width: 152px;
height: 31px; z-index: 5" id="Print">
<a href="javascript:framePrint('main');">
<img border="0" id="img1" src="images/buttonE.gif" height="30"
width="150" alt="Print" fp-style="fp-btn: Glass Capsule 1;
fp-transparent: 1" fp-title="Print"
onmouseover="FP_swapImg(1,0,/*id*/'img1',/*url*/'images/buttonF.gif')"
onmouseout="FP_swapImg(0,0,/*id*/'img1',/*url*/'images/buttonE.gif')"
onmousedown="FP_swapImg(1,0,/*id*/'img1',/*url*/'images/button10.gif')"
onmouseup="FP_swapImg(0,0,/*id*/'img1',/*url*/'images/buttonF.gif')"></a></div>
<p>&nbsp;</p>
<DIV
style="position:absolute;left:12px;top:107px;width:54px;height:19px;z-index:2"
align="left">
<FONT size="2" face="Arial">&nbsp;</FONT></DIV>
<DIV
style="position:absolute;left:12px;top:145px;width:54px;height:19px;z-index:3"
align="left">
&nbsp;</DIV>
<div style="position: absolute; left: 15px; top: 72px; width: 413px;
height: 27px; z-index: 4" id="JavaApp">

Much appreciated.
 
P

PieOPah

Well I have managed to HALF fix my problem.

Instead of using the function, I am using the following -

<a href="javascript:parent.focus('main');
javascript:parent.print('main');">

(I also have my image files linked in afterwards but that is not a
relevant part of the script).

What is happening now is that my Header frame is being printed and then
on a seperate page my Main frame is being printed.

I also tried

<a href="javascript:parent.focus('main'); parent.print('main');">

but this made no difference.

At least now I am printing (even though it is 2 frames instead of 1).
How can I modify this to only print the single frame?

Thank you.
 
V

VK

PieOPah said:
<a href="javascript:parent.focus('main');
javascript:parent.print('main');">

AFAIK window.print method doesn't take any arguments.

<a href="noscript.html"
onclick="
top.frames['main'].focus();
top.frames['main'].print();">Print</a>

with link located in your "menu" frame should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top