Forum Moderators: phranque

Message Too Old, No Replies

Print layer

Print layer

         

bmatth1

12:59 am on Sep 22, 2003 (gmt 0)

10+ Year Member



Is there a way, with javascript, to print the contents of a specific layer? (this does not seem to work: document.layer1.print();

THe name of the layer is layer1. I am hoping that someone has come across this. I am trying to prevent having a separate "printer friendly" page. My content for printing is all on a layer, and I would like to print that content only, without printing everything else on the page.
thanks you,
Bob

TGecho

2:01 am on Sep 22, 2003 (gmt 0)

10+ Year Member



If you set up a special print stylesheet, you could hide all of the other layers.

MonkeeSage

7:05 am on Sep 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you could do a document.write() with JavaScript and print the resulting wysisyg window...like...

<script type="text/javascript">
<!--
function printLayer(lname) {
var txt = document.getElementById(lname).innerHTML;
document.open();
document.write(txt);
document.close();
window.print();
// the previous line may need to be...
// document.print();
}
//-->
</script>

...

<div id="layer1">
Text is text, that's what it is. Text is text, that's what it is. Text is text, that's what it is. Text is text, that's what it is. Text is not speech, that's what it's not. Text is not speech, that's what it's not. Text is not speech, that's what it's not.
<a href="#" onclick="printLayer('layer1'); return false;">Print this layer</a>
<input type="button" value="Print this layer" onclick="printLayer('layer1');" />
</div>

I am not able to test this though, because I don't have a printer set up right now.

Jordan