Entry
How do I disable printing on a page?
Jul 28th, 2005 14:00
Eric Greenblatt, A N, Louis Cote, http://www.w3.org/TR/REC-CSS2
This is better handled using CSS. In the HEAD of the document, create
a style for the body tag using @media print, instructing that it should
not render anything:
<style type="text/css">
@media print {
body { display:none }
}
</style>
No JavaScript is necessary. I use this quite often so as not to render
items of no use on a printed page (e.g., sort buttons in column
headings and other UI elements).
Eric
---
ideally you cannot disable the menu option in the current window. you
either open the page in a new window using window.open() else use the
method below that I have used to print nothing. The main purpose is
that the data in the browser window should not be printed.
use this in the body tag
<body id="disable" onbeforeprint="open()" onafterprint="close()">
------ contents of the page ----
</body>
Into the script in the head part write the code for methods called in
body tag
<head>
<script>
function open(){
var hide = document.all.disable;
for(i=0; i<=hide.length; i++)
hide[i].style.display ='none';
}
function close(){
window.location.reload();
}
</script>
</head>