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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

innerHTML font size

Status
Not open for further replies.

shnazz

Technical User
Jul 27, 2004
22
US
Hi,

Yesterday I got some great help from a few members here, that included using the innerHTML property. When innerHTML is used for displaying content on a new page it seems to revert back to the default browsers font-size size and family regardless of style.

All other styles seem to work fine except the above two.
Can anyone help me??

function printMain() {
var pp = window.open();
pp.document.writeln("<html><head>");
pp.document.writeln("<link rel='stylesheet' type='text/css' href='../css/main.css'></head><body>")
var printMe = document.getElementById('main').innerHTML;
pp.document.writeln(printMe);
pp.document.writeln("</body></html>");
//pp.document.close();
pp.print();
}

 
It may be that the original style was based on the "innerHTML" text being inside of DIV tags. If that's the case, update one line to be:

var printMe = "<div>"+document.getElementById('main').innerHTML+"</div>";

--Dave
 
Hey...

The DIV whose inner html you're taking - apply that DIV's class to a new div in the new page.

For example:
[tt]
function printMain() {
var pp = window.open();
pp.document.writeln("<html><head>");
pp.document.writeln("<link rel='stylesheet' type='text/css' href='../css/main.css'></head><body>");
pp.document.writeln("<div class='THEDIVCLASS'>");
var printMe = document.getElementById('main').innerHTML;
pp.document.writeln(printMe);
pp.document.writeln("</div>");
pp.document.writeln("</body></html>");
//pp.document.close();
pp.print();
}[/tt]

*cLFlaVA
----------------------------
Ham and Eggs walks into a bar and asks, "Can I have a beer please?"
The bartender replies, "I'm sorry, we don't serve breakfast.
 
got it to work.

For some reason it does not work when I use your suggestions. I even went in to the real code and nested a div tag inside "main" with the formatting I wanted and that did not work.

I had to go down to the youngest parent of the actual text and add my formatting to it in my css style sheet, even though it inherits the styles in my regular page as it should. Ex: I had to go down to the actual <pre> tag and add a style parameter to it. Weird, but works.

Is it good practice to always assume that styles may not be inherited?

- shnazz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top