printing iframe

Discussion in 'Javascript' started by Marina Ferguson, Oct 27, 2003.

  1. Hi,

    I have a document with an iframe. The main doc has a "Print" button. The
    idea is that when the user clicks it, the contents of the iframe is printed.
    For some reason instead of the iframe I get a print out of the whole page.
    I am using IE6. I spent several hours searching the groups but didn't find
    anything that works. Even when I do this:

    iframe_name.focus();
    window.print();

    it still doesn't work.

    Thanks in advance for any help.

    Marina
     
    Marina Ferguson, Oct 27, 2003
    #1
    1. Advertising

  2. Marina Ferguson

    DU Guest

    Marina Ferguson wrote:

    > Hi,
    >
    > I have a document with an iframe. The main doc has a "Print" button. The
    > idea is that when the user clicks it, the contents of the iframe is printed.
    > For some reason instead of the iframe I get a print out of the whole page.
    > I am using IE6. I spent several hours searching the groups but didn't find
    > anything that works. Even when I do this:
    >
    > iframe_name.focus();
    > window.print();
    >
    > it still doesn't work.
    >
    > Thanks in advance for any help.
    >
    > Marina
    >
    >




    <script type="text/javascript">
    function PrintIframe()
    {

    frames["IframeName"].focus();
    frames["IframeName"].print();
    }
    </script>
    </head>

    <body>

    <iframe src="IframeDocument.html" name="IframeName" width="500"
    height="200" style="border:3px solid blue;">[Your user agent does not
    support iframes or is currently configured not to display iframes. If
    you're using Opera 6+, you can enable iframe with
    File/Preferences...Alt+P/Page style/Enable inline frames.]</iframe>

    <p><button type="button" onclick="PrintIframe();">Print only the
    iframe</button></p>

    When the user clicks that button, he will then need to select the
    "Options" tab of the print modal dialog window. In the Options tab, in
    the "Print frames" fieldset, the "Only the selected frame" radio button
    will be checked. Click the "Print" button in that Options tab and MSIE 6
    will print only the iframe.

    Tested, printed and working in MSIE 6 SP2 for Windows; I'll upload the
    demo files if needed.

    Also tested, printed and working in Netscape 7.1 Compact, K-meleon 0.8
    beta build 833 and Mozilla 1.5 final release (though there is an
    usability bug in those 3 browsers; the "Print frames" fieldset and "The
    selected frame" are disabled when they should not; the requested
    printing of the iframe is correct nevertheless).

    Tested and NOT working at all in Opera 7.21. I'll file a bug on this.

    DU
    --
    Javascript and Browser bugs:
    http://www10.brinkster.com/doctorunclear/
    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
    http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
     
    DU, Oct 28, 2003
    #2
    1. Advertising

  3. Marina Ferguson

    DU Guest

    DU wrote:

    > Marina Ferguson wrote:
    >
    >> Hi,
    >>
    >> I have a document with an iframe. The main doc has a "Print" button.
    >> The
    >> idea is that when the user clicks it, the contents of the iframe is
    >> printed.
    >> For some reason instead of the iframe I get a print out of the whole
    >> page.
    >> I am using IE6. I spent several hours searching the groups but didn't
    >> find
    >> anything that works. Even when I do this:
    >>
    >> iframe_name.focus();
    >> window.print();
    >>
    >> it still doesn't work.
    >>
    >> Thanks in advance for any help.
    >>
    >> Marina
    >>
    >>

    >
    >
    >
    > <script type="text/javascript">
    > function PrintIframe()
    > {
    >
    > frames["IframeName"].focus();
    > frames["IframeName"].print();
    > }
    > </script>
    > </head>
    >
    > <body>
    >
    > <iframe src="IframeDocument.html" name="IframeName" width="500"
    > height="200" style="border:3px solid blue;">[Your user agent does not
    > support iframes or is currently configured not to display iframes. If
    > you're using Opera 6+, you can enable iframe with
    > File/Preferences...Alt+P/Page style/Enable inline frames.]</iframe>
    >
    > <p><button type="button" onclick="PrintIframe();">Print only the
    > iframe</button></p>
    >
    > When the user clicks that button, he will then need to select the
    > "Options" tab of the print modal dialog window. In the Options tab, in
    > the "Print frames" fieldset, the "Only the selected frame" radio button
    > will be checked.


    .... and should be checked.

    The user does not have to go to the Options tab; it's just for
    verification. If he clicks the "Print" button in the "General" tab, the
    iframe only will be printed as well.

    DU
    --
    Javascript and Browser bugs:
    http://www10.brinkster.com/doctorunclear/
    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
    http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
     
    DU, Oct 28, 2003
    #3
  4. Thanks! That worked! However, it only works when the src of the iframe is
    on the same server as the main page. When I point to a page on a different
    server and put it in the iframe, it won't print. I get a JavaScript error
    "Access is denied." The server where iframe src file is located belongs to
    my company. Does anyone know what's going on and how can I work around it?

    Thanks,
    Marina
     
    Marina Ferguson, Oct 28, 2003
    #4
  5. Marina Ferguson

    DU Guest

    Marina Ferguson wrote:
    > Thanks! That worked! However, it only works when the src of the iframe is
    > on the same server as the main page. When I point to a page on a different
    > server and put it in the iframe, it won't print. I get a JavaScript error
    > "Access is denied." The server where iframe src file is located belongs to
    > my company. Does anyone know what's going on and how can I work around it?
    >
    > Thanks,
    > Marina
    >
    >


    Why do I get permission denied when accessing a frame/window?
    http://jibbering.com/faq/#FAQ4_19

    "The same origin policy works as follows: 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

    http://www.mozilla.org/projects/security/components/same-origin.html

    DU
    --
    Javascript and Browser bugs:
    http://www10.brinkster.com/doctorunclear/
    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
    http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
     
    DU, Oct 28, 2003
    #5
    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. Replies:
    0
    Views:
    728
  2. mi
    Replies:
    4
    Views:
    14,312
    dorayme
    May 21, 2008
  3. elca
    Replies:
    0
    Views:
    599
  4. Daedalous
    Replies:
    3
    Views:
    827
    Daedalous
    Jan 16, 2004
  5. Amit
    Replies:
    0
    Views:
    225
Loading...

Share This Page