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

Printing a window with Javascript

Status
Not open for further replies.

Streetdaddy

Programmer
Jun 10, 1999
161
0
0
AU
Lets say I have a page with a whole lot of HTML and part of it is inside:

Code:
      <span id=&quot;printArea&quot;>
      <table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
	<tr> 
	  <th colspan=&quot;5&quot;>Hello World</th>
	</tr>
	<tr> 
	  <td width=&quot;25%&quot; class=&quot;GRIDLB&quot;>Family</td>
	  <td class=&quot;GRID&quot; width=&quot;25%&quot;>Smith</td>

	  <td width=&quot;30%&quot; class=&quot;GRIDLB&quot;>Number of Customers</td>
	  <td width=&quot;20%&quot; class=&quot;GRID&quot;> 
	    <div align=&quot;right&quot;>25</div>
	  </td>
	  <td class=&quot;GRID&quot;> </td>
	</tr>
	<tr> 
	  <td class=&quot;GRIDLB&quot;>Family</td>

	  <td class=&quot;GRID&quot;>Jones</td>
	  <td class=&quot;GRIDLB&quot;>Number of Children</td>
	  <td class=&quot;GRID&quot;> 
	    <div align=&quot;right&quot;>1291</div>
	  </td>
	  <td class=&quot;GRID&quot;> </td>
	</tr>
	<tr> 
	  <td class=&quot;GRIDLB&quot;>Year</td>

	  <td class=&quot;GRID&quot;>01 Jul to 30 Jun</td>
	  <td class=&quot;GRIDLB&quot;>Bones</td>
	  
	  
	    <td class=&quot;GRID&quot;> 
	      <div align=&quot;right&quot;>1.4</div>
	    </td>
	    <td class=&quot;GRID&quot;>Km</td>
	  
	</tr>

      </table>
</span>

Then I have this function to open a new window and put the innerHTML of printArea in it.

Code:
function printPage() {
	var sContent = document.getElementById('printArea').innerHTML;	
	printWindow = window.open('', 'printWindow', 'scrollbars=yes,resizable=yes,toolbar=yes,status=yes,menubar=yes,location=yes');
	printWindow.document.write(sContent);
	printWindow.location.reload();
}

It looks find in IE (ofcourse) however in Netscape 7, after the new window reloads there are strange characters showing up.

Also, if I try to include a linked stylesheet in IE it is fine as the 'location' of the new window is the same as its parent, so it can link a stylesheet with no problems. But in NS7, it doesn't seem to be able to link to the stylesheet.

Does anyone have any tips about this?

Miles

Those Micros~1 guys sure know what they doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top