Home » Tutorials » CSS
Demo: Try to Print this page or Print
Preview |
Sometimes you might want to protect your online documents from printing. So in that case this little simple script might help. Please note that putting this script does not secure your document, users will still be able to 'copy it and paste it' in the word document and still be able to print it, if you want to secure your document you need other scripts that disable selecting or saving the page..etc.
<style type="text/css" media="print">
body { display: none; }
</style> |
Put the above script between the <head> </head> tags in your page. It will make your page empty when it
is printed. The code is fairly simple to understand, however let's go through one line at a time.
|
<style type="text/css"
media="print"> Here we declare that
the following script is a CSS Script and media is print
which means it is intended for paged, opaque material and
for documents viewed on screen in print preview mode.
|
|
|
body {
display: none;
}
Sets the body of the page to blank when the page is printed. |
Note:
This is especially useful when you don't want some of the
pages on your website to be printed and only be read online.
Of course you cant protect the content of the page with
this script alone, because cut and paste still would print
work here. That is another issue which is not discussed
here.
 |
Related CSS Tutorials |
| |
Hiding DIV layers after 5 seconds New
Learn how to hide all the div layers automatically after a specified time. |
| |
Creating and linking external CSS files
Learn how to create and attach external CSS file to a page. |
| |
Having different link colors on one page
Learn how to have more than one link color for the page. |
| |
Fixed Image Background for the page
Learn how to make centered background that stays even when you scroll the page. |
|
 |
|