Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a specific iframe 2

Status
Not open for further replies.

Nate1749

Programmer
Nov 1, 2002
204
US
Is there way to print just a specific iframe that I have. I read something about creating a CSS file and hiding the other objects, but since I have a banner on top and a menu nagiviation bar on the left, I would think that this would make my iframe an extra inch in on the left and an extra inch down on top.

The navigation bar is like this

Security Policies
600
600.48
608.72


and once someone clicks on a security policy it's loaded into the main iframe. Sometimes they may want these printed and I don't want the whole webpage getting in the way. My only alternative I can currently think of is to have a small link next to the #s on the navigation bar that opens the link up in a new window if they want to print it; but that kinda defeats the purpose of having the tables with iframes, doesn't it?

-Nate
 
I just found this ... Is it possible for me to modify this to direct it towards a specific iframe/window?

<script language = &quot;JavaScript&quot;>
document.write(&quot;<a href = 'javascript: window.print()'>Click to print</a>&quot;);
//-->
</script>
 
ok I did the css thing and it works great, but I found one flaw and I can't figure out how to fix it.

After someone clicks something in the menu (menu is also an iframe), if they directly go to print; it will print the menu. I opened up the html for the menu and added all the hide information to the menu html.

Now I select something from the menu, it appears in the other iframe (main.htm), and I directly go to print and it still prints the menu, except now it's just a blank page.

The only way to get the content printed in the other iframe (the main one where all the information is actually displayed), is to click in it first. Is there a way to automatically have that iframe selected when they go print no matter what?

-Nate
 
an another thing, when I go to Print Preview, it shows up like it should, but it just doesn't print out that way, weird huh?

Even if I click in the main.htm area first and print it, it prints the content in there (which I want), but not the banner that is on top in the print preview (which is weird).... wonder what the explanation for this is.
 
1) the banner at the top of your page, is this set to display in your print stylesheet if yes then it should print.
2) with regard to the iframes and the pages within them and the page holding them are they all linked to your master stylesheets.

Can you post a link to your site or failing that the code. It's not a lie if you believe it!

| |
 
I've been playing around in the meantime, I think the menu problem is related to the focus being set on the menu IFrame

I put the following in the iframe tag for the menu and it resolved the print problem

onmouseout=&quot;focus('nameofcontentsframe') It's not a lie if you believe it!

| |
 
Just had a look at your page and providing I don't click on the menu or click elsewhere after I do when I print or print preview I get the brinkster logo + your main contents page (I assume that is what was intended)
If you wish to hide the logo in your printed document set up a new class in your print.css

.image{display:none} in the print stylsheet
include the class=&quot;image&quot; in your image tag

Personal preference but I always prefer to use external stylesheets for both print and display
To prevent problems would always set
<style type=&quot;text/css&quot; media=&quot;screen&quot;> even when inlining the stylesheet
Regards
Ian It's not a lie if you believe it!

| |
 
ok on my main page where the iframe is refrenced, I now have:

<iframe src=&quot;menu.htm&quot; name=&quot;menu&quot; scrolling=&quot;auto&quot; width=&quot;100%&quot; height=&quot;100%&quot; frameborder=&quot;8&quot; onmouseout=&quot;focus('main')&quot;>Type error message for Netscape 4 and older browsers here.</iframe>


The good side is it prints what it says is in Print Preview. The bad side is, it's only one page (kind of like a screen shot with the other stuff omitted). The main itable (called 'main') can have many pages worth of content (i.e. 7pages if you click on Security Policies -> 668.42), but it's only printing what seems like a screen shot. Anyway how can I tell it to entire itable?

I intend to hide the logo, but I kept it in there so I can figure out this printing thing. I'm willing to have that banner part completly omitted if the entire iframe (main) would print. I guess I just wanted to see if I could do it both ways (logo + all content in main iframe; and just all content in main iframe).

-Nate
 
you could try

defining the height and width of the main contents frame in your stylesheets

use height=100% width=100% in your screen stylesheet

in the print stylsheet don't set any height attribute it should then automatically stretch to the end of the document it contains It's not a lie if you believe it!

| |
 
I had that design originally, but liked it better when the table with the border stayed the exact size the whole time; the stretching thing looks kinda bad. Thanks for all your help though. This is definitly going to be helpful in the future.

Perhaps javascript will allow me to just print a specific window (being the iframe 'main').

-Nate
 
It will only stretch in the printed version to the end of the document which will allow you to set scrolling=&quot;no&quot; in the print stylesheet which will get rid of the printed scrollbar if you print

the screen version would stay as is ie width=100% height= 100% It's not a lie if you believe it!

| |
 
I think that's exactly what I want. Unfortulately, it's a bit over my head right now. I'll keep trying though ..

I just started playing with css yesterday so... I don't have a print or screen stylesheet, but im working on it =)

Thanks, I wish I could award you more than 1 star!

-Nate
 
Don't worry about it I only started playing with stylesheets at the beginning of this year and although the site looks ok I made loads of errors but eventully worked out what to do and what not to do. I only looked into separate stylesheets for printing after someone else asked a similar question a couple of weeks ago.

The best way to think about using stylesheets is like this

1)They offer you excellent control over every element in your page ie color size position etc
2) They greatly simplify the layout of your page. ie you dont need tables to create smart looking layout which allows your page to load faster. You can if you want position anyything with pixel perfect accuracy ie iframes for example

<iframe id=&quot;menu&quot; name=&quot;menu&quot; style=&quot;position:absolute; left:10px; top:20px;width:130px; z-index:1&quot; framespacing=0 marginwidth=0 marginheight=0 scrolling=&quot;no&quot; frameborder=0 src=&quot;menu.html&quot; onmouseout=&quot;focus('main')&quot;></iframe>


3) using separate stylesheets for screen and print is effectively allowing you to design 2 distinctly different pages (including how the elements are positioned their color etc) in one page. It's not a lie if you believe it!

| |
 
What program do you use to do css/html in? Currently I'm doing everything in notepad and it's starting to get to me. Time for me to switch to a GUI.
 
I use 1stpage 2000, it supports css a provides help and info but basically you have to hand code the css it will insert the basic tags ie
<div></div>, <span></span>

it allows previews in external browsers etc and color codes the scripting etc
probably not ht e best but it's free


I'm going to have a look at this one when In get a chance but haven't got round to it yet

Regards
Ian It's not a lie if you believe it!

| |
 
::sigh:: im having 0 success rate, if anything i've done more damage than good!

Could you point me in the direction a little bit more. I guess elaborate on what you originally told me to do.

From my understanding there should be 3 stylesheets, a hide.css (for hiding content), a print.css, and a screen.css

In the screen stylesheet set height and width to 100%

In print.css set scrolling=&quot;no&quot; to get rid of scrollbar (i like this idea)

In the main itable where all the content is loaded into(called 'main'), have this in the header

<link rel=&quot;stylesheet&quot; href=&quot;general/screen.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot;>
<link rel=&quot;stylesheet&quot; href=&quot;general/print.css&quot; type=&quot;text/css&quot; media=&quot;print&quot;>


If my understanding is correct, then I must be doing my stylesheets wrong (or probably both are wrong); here's my print & screen stylesheet(used it based off my hide.css that I got from spoono.com).

my print.css

.print {
scrolling: no;
}


and my screen.css

.screen {
height: 100%;
width: 100%;
}
 
You only need 2 stylesheets, one for the screen and one for print

Screen Stylesheet

Body {background-color: #ffffff; background-image: none}
#menu{scrolling=&quot;auto&quot;}
#cont{width:100%;height:100%;scrolling=&quot;auto&quot;}

Print Stylesheet
Body {background-color: #ffffff; background-image: none}
#menu{display:none}
#cont{width:100%;scrolling=&quot;no&quot;}

Main Document
<head><title>Your Title</title></head>
<LINK rel=&quot;stylesheet&quot; type&quot;text/css&quot; href=&quot;print.css&quot; media=&quot;print&quot;>
<LINK rel=&quot;stylesheet&quot; type&quot;text/css&quot; href=&quot;screen.css&quot; media=&quot;screen&quot;>
<body>

<iframe id=&quot;menu&quot; name=&quot;menu&quot; framespacing=0 marginwidth=0 marginheight=0 width=&quot;120px&quot; hehight=&quot;100%&quot; frameborder=0 src=&quot;menu.html&quot; onmouseout=&quot;focus('cont')&quot;></iframe>

<iframe id=&quot;cont&quot; name=&quot;cont&quot; framespacing=0 marginwidth=0 marginheight=0 frameborder=0 src=&quot;contents.html&quot;></iframe>
</body>
</html>

I only put the frame info in the mainpage to keep the posting shorter and you can add other style attributes as desired

regards
Ian It's not a lie if you believe it!

| |
 
After extensivly trying to get the above code to work this weekend, I gave up and decided to just what you entered alone (rather than trying to enter it in mine). I am still having the same trouble, I have posted the files at


The name of the 5 files are
contents.htm
index.htm
menu.htm
print.css
screen.css

and they are all in that directory. If you to go Print Preview... Well I have no idea why it looks the way it does. I started with something small like trying to get the scrollbar to go away under print, but couldn't get that either.

I read up on CSS and saw that I was calling styles in two different ways, so I simply deleted all those styles just to make sure there were no conflicts.

index.htm is just a simple 1row, 2 cell table; first cell is menu.htm & 2nd cell is contents.htm

I referenced both CSS lines in all 3 htm files right after the HEAD.

This is what I've reduced the code down to:
screen.css
Body {background-color: #ffffff; background-image: none}
#menu{scrolling=&quot;auto&quot;}
#cont{width:100%;height:100%;scrolling=&quot;auto&quot;}

print.css
Body {background-color: #ffffff; background-image: none}
#menu{display:none}
#cont{width:100%;scrolling=&quot;no&quot;}

index.htm
<head><title>Test</title></head>
<LINK rel=&quot;stylesheet&quot; type&quot;text/css&quot; href=&quot;print.css&quot; media=&quot;print&quot;>
<LINK rel=&quot;stylesheet&quot; type&quot;text/css&quot; href=&quot;screen.css&quot; media=&quot;screen&quot;>
<body>
<table width=100% height=100%>
<tr>
<td>

<iframe id=&quot;menu&quot; name=&quot;menu&quot; framespacing=0 marginwidth=0 marginheight=0 width=&quot;120px&quot; height=&quot;100%&quot; frameborder=0 src=&quot;menu.htm&quot; onmouseout=&quot;focus('cont')&quot;></iframe>

</td><td>

<iframe id=&quot;cont&quot; name=&quot;cont&quot; framespacing=0 marginwidth=0 marginheight=0 frameborder=0 src=&quot;contents.htm&quot;></iframe>

</td></tr>

</table>
</body>
</html>


menu.htm
<HTML>
<HEAD>

</HEAD>

<LINK rel=&quot;stylesheet&quot; type&quot;text/css&quot; href=&quot;print.css&quot; media=&quot;print&quot;>
<LINK rel=&quot;stylesheet&quot; type&quot;text/css&quot; href=&quot;screen.css&quot; media=&quot;screen&quot;>

<BODY>
<BR><BR><BR><BR><BR>
<A HREF=&quot; TARGET=&quot;main&quot;>668.41</a>
<BR><BR><BR><BR><BR>5 lines
<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>10 lines
<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>15 lines
<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>20 lines
</BODY>
</HTML>


contents.htm
<HTML>

<HEAD>
</HEAD>

<LINK rel=&quot;stylesheet&quot; type&quot;text/css&quot; href=&quot;print.css&quot; media=&quot;print&quot;>
<LINK rel=&quot;stylesheet&quot; type&quot;text/css&quot; href=&quot;screen.css&quot; media=&quot;screen&quot;>

<BODY>

<TABLE WIDTH=&quot;100%&quot; HEIGHT=&quot;40&quot; BORDER=&quot;0&quot; CELLPADDING=&quot;0&quot; CELLSPACING=&quot;0&quot;>
<TR HEIGHT=&quot;20&quot;>
<TD bgcolor=&quot;000000&quot; nowrap></TD>
<TD bgcolor=&quot;000000&quot; nowrap></TD>
</TR>

<TR HEIGHT=&quot;20&quot;>
<TD WIDTH=350 ALIGN=LEFTT><font face=&quot;verdana&quot; size=&quot;2&quot; color=&quot;000000&quot; nowrap>
<A HREF=&quot;main.htm&quot;>Main</A> |
<A HREF=&quot;contact.htm&quot;>Contact Us</A> |
<A HREF=&quot;about.htm&quot;>About</A> |
<A HREF=&quot;help.htm&quot;>Help</A>
</TD>

<TD bgcolor=&quot;000000&quot; width=500><IMG SRC=&quot;images/curve.gif&quot; align=&quot;left&quot; border=&quot;0&quot; hspace=&quot;0 width=&quot;50&quot; height=&quot;20&quot; nowrap></TD>
</TR>

</TABLE>


<font face=&quot;verdana&quot; size=&quot;2&quot; color=&quot;000000&quot;><BR><BR>

Contents.htm

test scrolling<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>BR<BR>
test scrolling<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>BR<BR>
test scrolling<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>BR<BR>
test scrolling<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>BR<BR>
test scrolling<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>BR<BR>
</BODY>
</HTML>

That's it; I know it's long & sloppy (tried to clean it up).
-Nate
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top