My app contains a lot of data, so when I print it using the Chrome browser, it gets split across two pages. One of my colleagues suggested that I add a header to appear on the following pages, in case future data sets are also long. I’ve tried to do this, but I haven’t been able to figure it out yet.
(function () {
'use strict';
window.addEventListener('load', function () {
const originalHeader = document.querySelector('.row-gaia.clearFix-cybozu');
if (!originalHeader) return;
const clonedHeader = originalHeader.cloneNode(true);
clonedHeader.classList.add('print-duplicate-header');
clonedHeader.style.display = 'none'; // ซ่อนไว้ก่อน
document.body.appendChild(clonedHeader);
const style = document.createElement('style');
style.textContent = `
@media print {
.print-duplicate-header {
display: block !important;
position: absolute;
top: 1050px;
left: 0;
right: 0;
background: white;
padding: 10px 20px;
border-bottom: 1px solid #000;
}
body {
margin-top: 0 !important;
}
.print-duplicate-header:first-of-type {
display: none !important;
}
}`;
document.head.appendChild(style);
setTimeout(() => {
const docHeight = document.body.scrollHeight;
if (docHeight > 1122) {
clonedHeader.style.display = 'block';
}
}, 300);
});
})();