Skip to content

Instantly share code, notes, and snippets.

@jdanyow
Created September 27, 2021 16:50
Show Gist options
  • Save jdanyow/5acc670fbbef67036a4aae99577b033a to your computer and use it in GitHub Desktop.
Save jdanyow/5acc670fbbef67036a4aae99577b033a to your computer and use it in GitHub Desktop.
Printing example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Standard page title</title>
<style>
@media print {
.hidden-print {
display: none;
}
.page-break-before-always {
page-break-before: always;
}
}
</style>
</head>
<body>
<h1>Hello world!</h1>
<p>This paragraph will print</p>
<p class="hidden-print">This paragraph will not print</p>
<p class="page-break-before-always">This paragraph will print on another page</p>
<button class="hidden-print" onclick="window.print()">Print this page</button>
<script>
addEventListener('beforeprint', () => document.title = 'This title was customized for printing');
addEventListener('afterprint', () => document.title = 'This title was customized for printing');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment