www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 05-06-2004, 01:03 PM
    elemental elemental is offline
    Registered User
     
    Join Date: May 2004
    Posts: 7
    Question Problems printing an iFrame

    Firstly I'll own up to not being a code monkey, so I really do need some help.

    I require a javascript code to focus and print an iFrame called 'stocklist_content' I need to be able to do this by placing a link in the parent frame and a seperate within the iFrame itself.

    I have found a few articles on the subject but no complete examples of the required code.

    Can anyone provide a full example?

    Thanks in advance, elemental
    Reply With Quote
      #2  
    Old 05-06-2004, 01:11 PM
    Kor's Avatar
    Kor Kor is offline
    Red Devil Moderator
     
    Join Date: Dec 2003
    Location: Bucharest, ROMANIA
    Posts: 11,143
    focus() the iframe than print() it (by the way, print() method works on IE only).
    Reply With Quote
      #3  
    Old 05-06-2004, 01:14 PM
    sciguyryan's Avatar
    sciguyryan sciguyryan is offline
    I've passed 1,000 posts!
     
    Join Date: Jul 2003
    Location: Wales
    Posts: 1,390
    Try something like this:

    Code:
    <script type="text/javascript">
    <!--
    function PrintF(){
    var IFRAME = document.getElementById("MyIframe");
    IFRAME.print();
    }
    //-->
    </script>
    Note: remember to change the ID ("MyIframe") there to your frames id and, to add the event to something e.g. a button like so:

    Code:
    <form action="" method="post">
    <input type="button" value="Print!" OnClick="PrintF();" />
    </frame>
    __________________
    RyanJ (Ryan Jones)

    General Links:
    ( Jick's Blog | W3C Validation | W3C CSS Validation )
    Manuals:
    ( PHP Manual | MySQL Manual )

    Ways to help with tsunami relief
    Reply With Quote
      #4  
    Old 05-06-2004, 01:39 PM
    elemental elemental is offline
    Registered User
     
    Join Date: May 2004
    Posts: 7
    Exclamation

    I'm very impressed with the prompt replies, thanks.

    sciguyryan I have used your code e.g.

    http://www.sentinalcars.com/stocklist.html

    but get the following error in Explorer 6:

    IFRAME.print();
    Quote:
    Error: Object doesnt support this property or method on line 45
    Line 45 being:

    Quote:
    IFRAME.print();
    err....
    Reply With Quote
      #5  
    Old 05-06-2004, 01:42 PM
    elemental elemental is offline
    Registered User
     
    Join Date: May 2004
    Posts: 7
    Dam sorry typo in URL

    http://www.sentinelcars.com/stocklist.html

    elemental
    Reply With Quote
      #6  
    Old 05-06-2004, 02:47 PM
    sciguyryan's Avatar
    sciguyryan sciguyryan is offline
    I've passed 1,000 posts!
     
    Join Date: Jul 2003
    Location: Wales
    Posts: 1,390
    Ok, sorry about that it seems I used an incorrect idea

    try this:

    Code:
    <script type="text/javascript">
    <!--
    function PrintF(){
    document.FrameName.focus();
    document.FrameName.print();
    }
    //-->
    </script>
    Remember to change the names though
    __________________
    RyanJ (Ryan Jones)

    General Links:
    ( Jick's Blog | W3C Validation | W3C CSS Validation )
    Manuals:
    ( PHP Manual | MySQL Manual )

    Ways to help with tsunami relief
    Reply With Quote
      #7  
    Old 05-06-2004, 03:25 PM
    elemental elemental is offline
    Registered User
     
    Join Date: May 2004
    Posts: 7
    Exclamation

    No change

    Quote:
    Error: Object doesn't support this property or method
    Refers to Line 44:

    [quote]document.stocklist_content.print();[\QUOTE]

    Next...
    Reply With Quote
      #8  
    Old 05-06-2004, 03:41 PM
    sciguyryan's Avatar
    sciguyryan sciguyryan is offline
    I've passed 1,000 posts!
     
    Join Date: Jul 2003
    Location: Wales
    Posts: 1,390
    Thats odd, when I looked this up that was the syntax used on another site :S

    If I get any other ideas I'll post them for you to try.
    __________________
    RyanJ (Ryan Jones)

    General Links:
    ( Jick's Blog | W3C Validation | W3C CSS Validation )
    Manuals:
    ( PHP Manual | MySQL Manual )

    Ways to help with tsunami relief
    Reply With Quote
      #9  
    Old 05-06-2004, 03:45 PM
    fredmv's Avatar
    fredmv fredmv is offline
    Moderator
     
    Join Date: Jul 2003
    Location: Boston Area, Massachusetts
    Posts: 3,499
    http://www.webdeveloper.com/forum/sh...900#post130635
    Reply With Quote
      #10  
    Old 05-06-2004, 04:08 PM
    elemental elemental is offline
    Registered User
     
    Join Date: May 2004
    Posts: 7
    Thumbs up

    We're back on track, thanks fredmv.

    Now the iframe content prints but not fully... it cuts off at the bottom of the printed page border...

    Any ideas?
    Reply With Quote
      #11  
    Old 05-07-2004, 05:38 PM
    elemental elemental is offline
    Registered User
     
    Join Date: May 2004
    Posts: 7
    Unhappy

    The responses have stopped flowing... ok let me rephraise the question before I abandon iframes forever. How do I force the browser to print the entire contents of the iframe?

    thanks in advance, elemental.
    Reply With Quote
      #12  
    Old 05-07-2004, 05:49 PM
    Vladdy's Avatar
    Vladdy Vladdy is offline
    Helper, not pleaser
     
    Join Date: Nov 2002
    Location: Nashua, NH
    Posts: 3,222
    Abandoning iframes is the best idea of the thread so far (most probably you were using them for all the wrong reasons anyway). :thumbsup:
    __________________
    Vladdy

    Working web site is not the one that looks the same in a few graphical browsers, but the one that adequately delivers its content to any device accessing it.
    Reply With Quote
      #13  
    Old 02-20-2008, 06:11 PM
    ecline ecline is offline
    Registered User
     
    Join Date: Feb 2008
    Posts: 2
    my way

    Tested in IE7

    Code:
    <head>
    <script type="text/javascript">
    function ClickHereToPrint(){
        try{ 
            var oIframe = document.getElementById('ifrmPrint');
            var oContent = document.getElementById('divToPrint').innerHTML;
            var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
            if (oDoc.document) oDoc = oDoc.document;
    		oDoc.write("<html><head><title>title</title>");
    		oDoc.write("</head><body onload='this.focus(); this.print();'>");
    		oDoc.write(oContent + "</body></html>");	    
    		oDoc.close(); 	    
        }
        catch(e){
    	    self.print();
        }
    }
    </script>
    </head>
    
    
    <body>
    
    <a onclick="ClickHereToPrint();">Print</a>
    
    	<iframe id='ifrmPrint' src='#' style="width:0px; height:0px;"></iframe>
    	<div id="divToPrint">
    		content
    	</div>
    </body>
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 05:48 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.