Connecting Tech Pros Worldwide Help | Site Map

printing iframe

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 11:24 AM
Marina Ferguson
Guest
 
Posts: n/a
Default printing iframe

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



  #2  
Old July 20th, 2005, 11:24 AM
DU
Guest
 
Posts: n/a
Default Re: printing iframe

Marina Ferguson wrote:
[color=blue]
> 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
>
>[/color]



<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

  #3  
Old July 20th, 2005, 11:24 AM
DU
Guest
 
Posts: n/a
Default Re: printing iframe

DU wrote:
[color=blue]
> Marina Ferguson wrote:
>[color=green]
>> 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
>>
>>[/color]
>
>
>
> <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.[/color]

.... 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

  #4  
Old July 20th, 2005, 11:25 AM
Marina Ferguson
Guest
 
Posts: n/a
Default Re: printing iframe

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


  #5  
Old July 20th, 2005, 11:25 AM
DU
Guest
 
Posts: n/a
Default Re: printing iframe

Marina Ferguson wrote:[color=blue]
> 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
>
>[/color]

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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.