window.print and iframe

Discussion in 'HTML' started by Lamberti Fabrizio, May 26, 2004.

  1. Hi all,
    I've got this problem.

    I've an ASP file, named content.asp, with inside an input button and a
    iframe that loads another asp file, named iframe.asp

    I'd like printing iframe.asp using the button inside content.asp.

    The size of iframe object inside content.asp is smaller than the real size
    of iframe.asp so I can't use JSCRIPT code window.print for the input button.

    How can I solve my problem ?

    regards
    Lamberti Fabrizio, May 26, 2004
    #1
    1. Advertising

  2. Lamberti Fabrizio

    DU Guest

    Lamberti Fabrizio wrote:

    > Hi all,
    > I've got this problem.
    >
    > I've an ASP file, named content.asp, with inside an input button and a
    > iframe that loads another asp file, named iframe.asp
    >
    > I'd like printing iframe.asp using the button inside content.asp.
    >
    > The size of iframe object inside content.asp is smaller than the real size
    > of iframe.asp so I can't use JSCRIPT code window.print for the input button.
    >
    > How can I solve my problem ?
    >
    > regards
    >
    >



    Assuming you have this markup in your content.asp file:

    <p><button type="button" onclick="PrintIframe();">Print the content of
    the iframe</button></p>
    <iframe name="IframeName" src="iframe.asp" ...></iframe>

    then in your <head> include this:

    <script type="text/javascript">
    function PrintIframe()
    {
    frames["IframeName"].focus();
    frames["IframeName"].print();
    }
    </script>

    1- Note that content.asp and iframe.asp must share the same domain
    otherwise you'll be prevented to print because of the scripting across
    domain security constraint:
    "when loading a document from one origin, a script loaded from a
    different origin cannot get or set specific properties of specific
    browser and HTML objects in a window or frame"
    http://devedge.netscape.com/library/manuals/2000/javascript/1.3/guide/sec.html#1015705

    2- Last time I checked this issue (~ 6 months ago or so), Opera 7.x was
    not printing iframe but this could have been fixed since then. The code
    works for NS 7.x, Mozilla 1.3+, MSIE 6.

    DU
    DU, Jun 1, 2004
    #2
    1. Advertising

  3. Lamberti Fabrizio

    lebohang

    Joined:
    Mar 2, 2009
    Messages:
    1
    Printing Iframe from a different frame.

    Hi,

    Just to add to this post. If the print button is on a different frame from the frame that contains your iframe (but in the same domain). then you can use:

    parent.frames['frameName'].window.frames['IframeName'].focus();
    parent.frames['frameName'].window.frames['IframeName'].print();

    Hope this helps.

    lebohang, Mar 4, 2009
    #3
  4. Lamberti Fabrizio

    AGN

    Joined:
    Jan 25, 2011
    Messages:
    1
    i cant print from iframe.print() in a pdf file in IE.please give me a solution,i tried self.print(),window.print etc.
    AGN, Jan 28, 2011
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keto
    Replies:
    0
    Views:
    897
  2. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    335
    David Cournapeau
    Dec 30, 2008
  3. Scott
    Replies:
    6
    Views:
    919
    [MSFT]
    Apr 14, 2004
  4. Daedalous
    Replies:
    3
    Views:
    659
    Daedalous
    Jan 16, 2004
  5. FatBo
    Replies:
    0
    Views:
    462
    FatBo
    Dec 20, 2005
Loading...

Share This Page