View Full Version : printing problem in frames using javascript

09-09-2008, 06:45 PM
hi forum
i m facing a problem regarding printing withing the frames page
i have a main frame page. which has on the left the menu html page loaded and on the right the target content page.
when i try to open a page on the right and print two different pages using iframes it does not work ,
on the contrary when i load the page without frames it does the print job perfectly.i fail to understand why this is happening
i m posting the partial code as the main code is too long and is not relevant for this issue.
the following is the code
pls suggest me some way out

<script language="JavaScript">

function printPg(ifrmname){
<iframe name="one" width="0" height="0" frameborder="0" src="E:/anand/program/final/databaseos/data/custprint.htm"></iframe>

<iframe name="two" width="0" height="0" frameborder="0" src="E:/anand/program/final/databaseos/data/factprint.htm"></iframe>

<a href="#" onclick="printPg('one');return false;">Print Customer Copy</a>

<a href="#" onclick="printPg('two');return false;">Print Factory Copy</a>

---smile always

09-10-2008, 06:21 AM


refers to an iframe on the top page. If this script is in a frameset and the iframe is on the page with this script, the top page (the frameset) will not have the desired iframe.

You have other choices. Using parent might work, if the script is in one of the iframes:


But, if the script is on the page containing the iframes, use window:


In other words, you must refer to the proper window in order to find its frames or iframes:

top - always refers to the window of the top most document, regardless of whether there are thousands of levels of nesting or only one window.
window - always refers to the current frame or window in which the current document resides.
parent - refers to the next window or frame up from the one in which the current document resides, unless there is no higher window or frame, then it refers to the window of the current document.

Added Later:

You might just want to do a test:

<script type="text/javascript">
function printPg(ifrmname){
var f = top.frames[ifrmname] || window.frames[ifrmname] || parent.frames[ifrmname] || null;

09-10-2008, 05:06 PM
thanks for the info and yes the problem was solved.
after posting this problem i tested the same thing without top.
and just used frames[ifrmname] and it worked:)
so m happy and sure i will also use the above mentioned solution as it gives a chance of no failure of the function
thanks a lot
smile always