Click to See Complete Forum and Search --> : Target an iframe for printing
I am not able to target the iframe for printing. The print icon is working but it is printing the whole page (main page & iframe). When printing using this icon some of the iframe's content is cut off. The code works if I placed the printer icon and script on the page within the iframe but it isn't working when I try to target it from the main page using the script below. Please Help...
<script language=javascript>
<!-- Begin
function printWindow() {
bV = parseInt(navigator.appVersion);
if (bV >= 4) document.main_content.print();
}
// End -->
</script>
<body>
<iframe name= "main_content" frameborder= "0" scrolling="auto" marginheight= "1" align="top" height = "100%" WIDTH="100%" src="http://ednat.sce.com/gid/redirect.shtml"></iframe>
<a href="javascriptrintWindow()"><img src="images/5xp_right_placeholder4.gif" width="136" height="70" border="0" alt="Print This Page"></a>
</body>
jdavia
04-01-2003, 01:05 PM
Originally posted by dp11
I am not able to target the iframe for printing. The print icon is working but it is printing the whole page (main page & iframe). When printing using this icon some of the iframe's content is cut off. The code works if I placed the printer icon and script on the page within the iframe but it isn't working when I try to target it from the main page using the script below. Please Help...
Try the complete address including the iframe name. You might be targeting the page not the iframe.
A couple of things... First of all, by checking to see if the browser version is greater than 4, you are eliminating browsers such as Mozilla..
Then, try changing this document.main_content.print(); to top.main_content.print();
A couple of things... First of all, by checking to see if the browser version is greater than 4, you are eliminating browsers such as Mozilla..
Are you suggesting that I use a smaller number than 4?
Then, try changing this document.main_content.print(); to top.main_content.print();
I changed it to top.main_content.print(); and it still printing out both the main page and the iframe.
Try the complete address including the iframe name. You might be targeting the page not the iframe.
Could you further explain what you mean by complete address?
All help is appreciated!!
jdavia
04-01-2003, 04:07 PM
Originally posted by dp11
Could you further explain what you mean by complete address?
All help is appreciated!!
The exact location from the parent folder to the final folder where the iframe file is on the server in relation to the page you are calling it from.
jdavia
04-01-2003, 04:44 PM
Since documents in inline frames are treated as separate documents, the destination (href) of each link in a document is
interpreted independently of the situation that the document appears inside an inline frame. For example, a reference
like href="#foo" refers to location named foo in that document, not in the embedding document. So the example
discussed above uses, when providing a link from inside an inline to a location named target in this main document, not
only target="_top" but also href="iframe.html#target" instead of href="#target". (It can use the relative
URL iframe.html though, since in this case the embedded document resides in the same directory, therefore with the
same path part in its URL, as the embedding document.)
Originally posted by dp11
Are you suggesting that I use a smaller number than 4?Why are you doing browser detection at all?
You could perhaps try this... Not sure if it will work, but give it a shot. top.main_content.window.print();
It was part of the code that I got off of another website. I dumped the browser check and now all I have is this - yet it is still printing both the main page and the embedded iframe.
<body>
<iframe name= "main_content" frameborder= "0" scrolling="auto" marginheight= "1" align="top" height = "100%" WIDTH="100%" src="http://ednat.sce.com/gid/redirect.shtml"></iframe>
<a href="#" onclick="top.main_content.window.print();"><img src="images/5xp_right_placeholder4.gif" width="136" height="70" border="0" alt="Print This Page"></a>
</body>
I think I have found a work-around to my problem by using the code below.
<a href="#" onclick="top.main_content.window.focus();top.main_content.window.print();"><img src="images/5xp_right_placeholder4.gif" width="136" height="70" border="0" alt="Print This Page"></a>
Do you guys foresee any problems that may occur from using this? Thanks!
jdavia
04-01-2003, 10:13 PM
Here is a page that may tell you what you ran into.
http://www.cs.tut.fi/~jkorpela/html/iframe.html
I would put a print link in the iframe as a solution. Then the problem is over.
Iframes have an advantage over frames in some ways, and many dis-advantages in other ways.
Thanks guys for all of your help!
Although both ways seems to work and produce the desired results
top.main_content.window.focus();
top.main_content.window.print();
&
self.iframeName.focus();
self.iframeName.print();
I am going to go with the latter (DaveClark's) Suggestion. Again, I appreciate all of you help!