...

View Full Version : [SOLVED] How do I send part of a page to the printer?



mlse
03-06-2005, 01:44 PM
Hi.

I am am javascript virgin. I would like to send part of a webpage to the printer when the user clicks on a "print" button.

I have tried stuff like this:

<layer name='print_me'>
This text is the only thing I want to print.
</layer name>

<input type='button' onclick='document.layers["print_me"].print()' value='Print'>

The trouble is, it doesn't matter what I put in the "onclick" tag for the input, I just can't get the stuff in the layer to print!! :mad: The best I have been able to do so far is 'window.print()', which prints the entire contents of the window. Which is not what I want. I am sure that what I do want to do is actually frustratingly simple, but I just don't know the syntax!

On the same (well, a similar) note, is there a top-level object in Javascript (much like the t-variable in LISP) which contains a recursive print method, allowing it and all it's children to be written to standard out (effectively tracing the entire language, showing functional and member variable inheritance).

Any help would be much appreciated!

TIA,
Mike.

vwphillips
03-06-2005, 02:25 PM
variations of



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
function Print(){
divs=document.getElementsByTagName('DIV');
for (i=0;i<divs.length;i++){
if (divs[i].title!='printMe'){
divs[i].style.display='none';
}
}
print();
for (i=0;i<divs.length;i++){
divs[i].style.display='block';
}

}
//-->
</script>

</head>

<body>
<div>
sssssssssssssss<br>
<img src="http://www.vicsjavascripts.org.uk/StdImages/One.gif">
<input type="button" name="" value="Print" onclick="javascript:Print();">
</div>
<div title="printMe" >
Print Me
</div>
</body>

</html>



may assist

mlse
03-06-2005, 02:50 PM
Joy!

:D :D :D

Thanks very much.

:thumbsup:

glenngv
03-07-2005, 11:54 AM
Pure CSS print (http://wsabstract.com/dhtmltutors/cssmedia2.shtml)

mlse
03-07-2005, 12:09 PM
Nice. Very neat!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum