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

Printing a layer 2

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
I have created a layer using the <div> tag. The layer includes a print button but this triggers a print of the entire page. Is there a way to print just the layer defined in the <div> tag.

Thanks in advance.
 
No. Div is just a part of the website, not a whole different entity. You could however hide everything on the page except that div for the print. Look at media attribute in link tag.
 
Thanks. Ideally I'd have liked the user to have had the option to print the entire page or just the layer. Perhaps I was just hoping for too much! I had come across the media attribute in thread215-642736 which is discussing a different problem that happens to be in the context of layers but this is presumably the sort of solution you are suggesting.
 
Since you have a print button, you could actually do it. Make two print stylesheets, default and custom (for printing just the div) and put it on the page like this:
Code:
<link rel="stylesheet" type="text/css" href="defaultprint.css" id="printingCSS" media="print" />
Then make two stylesheets:
defaultprint.css should have everything on
divprint.css should look like:
Code:
* {
  display: none;
}

div#myDiv {
  display: block;
}
Of course your div (layer) would have to have id of myDiv in this case.

In your print button, add:
Code:
document.getElementById('printingCSS').href = 'divprint.css';
document.print();
document.getElementById('printingCSS').href = 'defaultprint.css';
Something like that should work.
 
This is a very quick and dirty way
Code:
<html><head>
<style media="print">
.noPrint {display:none;}
</style>
</head>
<div class = "print"> this will be your print layer</div>
<div class = "noprint">this layer won't print <a href = # onClick="window.print()">
this could be a button</a></div>
<body>
</html>
Hope this helps.

Glen
 
Sorry - I've been distracted. Thanks for the input - I will experiment with these suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top