...

View Full Version : print preview in new window



marshallhansen
06-01-2005, 10:23 PM
I am trying to do a print preview in a new window. I want only the main content area to come up in the new window. I have a script that will grab everything inside a div and throw it in a new window, but it will not transfer anything inside any other tags inside the div.

This is my function that I call...

<script LANGUAGE="JavaScript">
function displayHTML() {
var inf = document.getElementById('printarea').innerHTML;
win = window.open("print.htm", 'popup', 'toolbar = no, status = no');
win.document.write(inf + "<br /><a href='javascript:print()'>print</a>");
win.document.close();
}
</script>

What doesn't work though is if I have
<div id="printarea">adf
<table><tr><td>content here</td></tr></table>
</div>

With this what I get in the new window is the "adf" not the table.

WMJB
06-02-2005, 03:28 AM
Strange... the following worked as expected for me....?


<html>
<head>
<script>
function displayHTML() {
var inf = document.getElementById('printarea').innerHTML;
win = window.open("print.htm", 'popup', 'toolbar = no, status = no');
win.document.write(inf + "<br /><a href='javascriptrint()'>print</a>");
win.document.close();
}

</script>
</head>
<body>
<button onclick="displayHTML()" >print preview</button>
<div id="printarea">adf
<table><tr><td>contents of table here</td></tr></table>
</div>

</body>
</html>

glenngv
06-02-2005, 04:04 AM
Why did you start a new thread when you already posted this (http://www.codingforums.com/showthread.php?t=60013)? Have you considered my suggestion in that thread?

marshallhansen
06-02-2005, 10:21 PM
I did look at your suggestion and that would be the ideal solution. This is the situation though....I'm inheriting a poorly coded site and the client doesn't want to do a full recode. They are also insistant that there be a preview, that is not the standard print preview. I'm sure you understand when clients get something set in their mind and they won't let it go.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum