By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

printing iframe

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
DU
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/doctorunc...e7Section.html

Jul 20 '05 #2

P: n/a
DU
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/doctorunc...e7Section.html

Jul 20 '05 #3

P: n/a
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
Jul 20 '05 #4

P: n/a
DU
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/...c.html#1015705

http://www.mozilla.org/projects/secu...me-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/doctorunc...e7Section.html

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.