printing iframe

M

Marina Ferguson

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
 
D

DU

Marina said:
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
 
D

DU

DU said:
Marina said:
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
 
M

Marina Ferguson

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
 
D

DU

Marina said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top