devxlogo

Printing DHTML (CSS) in Netscape 4.0+

Printing DHTML (CSS) in Netscape 4.0+

Question:
I’ve put together an intranet site that uses JavaScript functions that put together a page. For example, the header section, body section, footer section, sidebar, and so on are called JavaScript functions. The sidebar and main body functions are displayed as DHTML style sheets. I need the content in the body or the whole page to print. Either will do. The problem is that it prints okay in Internet Explorer but when I try to print it in Netscape I get the error message, “There are no pages to print.” Also I don’t get side scroll bars in Netscape. Unfortunately, my client is a Netscape company. Can you help me?

Answer:
The problem that you’re running into comes from the ways that the two browsers maintain information about their current state. In Internet Explorer, the browser actually manipulates the internal document whenever a change is made, which is part of the reason that you can set the innerHTML of any entity within the page and still have it appear in print. With the Netscape browser, on the other hand, the system only maintains the initial state of the document, and any modifications made are changes to the output, not the document. In other words, if I set the contents of a layer once the document has been displayed, I only change the display?the document remains static.

One upshot of this situation comes with printing. If you print out a document from Internet Explorer, the internal print engine traverses the current document’s representation and reformats it to fit page specifications. Thus, if you use .innerHTML, the new value will get output. With Netscape, only the original HTML is available for reformatting to the printer, not any changes made since then by JavaScript.

See also  Why ChatGPT Is So Important Today

The solution, unfortunately, isn’t a pretty one. In order to output a modified page to the printer, you need to create the same document in HTML. Luckily it sounds like you’ve already done most of the precursor work for this task yourself. First you need to create a buffer of HTML output that mirrors the document currently in memory. Then you open a new window and pump the contents of the new pseudo-page into the window as a separate document. In general, it’s best to separate the accumulation of the text (or the building of the page) from the mechanics of opening the window and displaying the contents.

As I said, it’s not a terribly elegant solution, but until Netscape formally adopts the W3C HTML Object model sometime later this year with Netscape 5, it’s about the only option that’s available.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist