...

View Full Version : How to print multiple nested divs



Homesick
08-25-2010, 08:49 AM
Hi guys ,, I am new here

could you please help me in this:

I have multiple divs something like this


<div id="div1">
<div id="div2">
<div id="div3">
....
</div>
</div>


I want JavaScript code to print div1 with all nested divs as well

I tried using the following code but it only print div1 content



var printContent = document.getElementById('div1');

var windowUrl = 'about:blank';

var uniqueName = new Date();

var windowName = 'Print' + uniqueName.getTime();

var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=200,height=200');

printWindow.document.write(printContent.innerHTML);

printWindow.document.close();

printWindow.focus();

printWindow.print();

printWindow.close();



so please tell me how to do such operation ??

Old Pedant
08-25-2010, 09:29 PM
Why don't you *start* by seeing if your printWindow *DISPLAYS* the nested DIVs???

That is, change this line:


var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=200,height=200');
to simply this:


var printWindow = window.open(windowUrl, windowName );


And then (for now) remove the two lines


printWindow.print();
printWindow.close();

What does that popup window look like? Does it contain all the nested div content?

If not, then of course it can't be printed.

Time to diagnose why getting the innerHTML of div1 isn't enough.

jan lee
08-26-2010, 09:56 PM
Old Pedant,

This thread is close with my thread (posted in ASP forum) regarding save to database the DIV contents. Taking into account the print mode, would be possible print to a file, like .pdf?

regards

Jan Lee

Old Pedant
08-26-2010, 10:24 PM
Printing to a PDF file requires a component. Which costs money. But yes, you could.

You could certainly print to a text file, of course.

jan lee
08-27-2010, 03:19 AM
How I do it?

Well, I am trying (still) solve that problem. To save into a text file could be fine.

Regards

Jan Lee

Old Pedant
08-27-2010, 08:36 PM
Go back to the ASP thread. This doesn't belong in the JavaScript forum.

As I said there, you *could* save the <div> contents in the database, but why? It would be unformatted and nearly useless for any kind of searching at a later time. Explain the purpose of this, in that ASP thread.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum