Thanks, you are right, all events are lost, here is the solution:
function upDateYear() {
const date = new Date();
const currentYear = date.getFullYear();
// Update HEAD content
const head = document.getElementsByTagName("HEAD")[0];
if (head) {
head.childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE) {
node.nodeValue = node.nodeValue.replace(/CurrentYear/g, currentYear);
}
});
}
// Update the content of the BODY
const body = document.getElementsByTagName("BODY")[0];
if (body) {
const replaceTextNodes = node => {
if (node.nodeType === Node.TEXT_NODE) {
node.nodeValue = node.nodeValue.replace(/CurrentYear/g, currentYear);
} else if (node.nodeType === Node.ELEMENT_NODE) {
node.childNodes.forEach(replaceTextNodes);
}
};
replaceTextNodes(body);
}
}