Results 1 to 3 of 3

Thread: printing problem in frames using javascript

  1. #1
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default printing problem in frames using javascript

    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
    Code:
    <script language="JavaScript">
        
    function printPg(ifrmname){
    			if(top.frames[ifrmname]){
    				top.frames[ifrmname].focus();
    				top.frames[ifrmname].print();
    			}
    		}
    </script>
    <td>
    <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>
    </td>
    ---smile always
    anand

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This:

    Code:
    top.frames[ifrmname]
    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:

    Code:
    parent.frames[ifrmname]
    But, if the script is on the page containing the iframes, use window:

    Code:
    window.frames[ifrmname]
    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:

    Code:
    <script type="text/javascript">
    function printPg(ifrmname){
    var f = top.frames[ifrmname] || window.frames[ifrmname] || parent.frames[ifrmname] || null;
    			if(f){
    				f.focus();
    				f.print();
    			};
    		};
    </script>
    Last edited by jscheuer1; 09-10-2008 at 06:35 AM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    meenakshi (09-10-2008)

  4. #3
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    hi
    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
    anand

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •