Remove the default browser header and footer when printing HTML
javascriptYou can remove the default browser header and footer when printing HTML by using the @media print CSS rule. Here’s an example of how to do it:
@media print {
/* Hide the default header and footer */
@page {
size: auto;
margin: 0;
}
/* Show only the content to be printed */
body {
margin: 0;
padding: 0;
}
}
In this example, we use the @media print rule to specify the styles to be applied when the content is printed.
We use the @page rule to hide the default header and footer by setting the page size to auto and the margin to 0. This removes any default margins or headers/footers that may be added by the browser.
We use the body element to show only the content to be printed by setting the margin and padding to 0. This removes any extra space around the content and ensures that only the content is printed.
You can add this CSS to your HTML file using a
Other Article on Tag javascript
- - Adding and removing content in jQuery
- - Are JavaScript strings immutable? Do I need a "string builder" in JavaScript?
- - Can I change the Dojo namespace to something other than dojo
- - Can I prevent user pasting Javascript into Design Mode IFrame
- - dynamically create html element in javascript
- - Find XY of an HTML element with JavaScript
- - How can I upload files asynchronously with jQuery
- - How can you display Typing Speed using Javascript or the jQuery library
- - How do you capture mouse events in firefox
- - How to auto-size an iFrame