I want to display a certain text (an ID) on each page printed by the browser, like a header in a Word document. From looking around there are a multitude of hacks around, which seem not to be working for all browsers and web sites (How to use HTML to print header and footer on every printed page of a document?).
I was thinking I could change the title of the web page before printing, to display the ID in the auto header added by the browser, and after printing reset it to its original title (the ID should not be there in the title upon leaving the page, to be saved by browser history). It is possible to listen to print events in all browsers: https://stackoverflow.com/a/3619706/198953 however when trying it out in chrome with the following code:
var mqList = window.matchMedia("print");
mqList.addListener(function (mql) {
if (mql.matches)
document.title = "a certain text";
else
document.title = origTitle;
});
the page's title is updated after the print preview shows. Now, I can set the title on entering the page to the ID, but I cannot have the ID to be saved by browser history. Are there no fool-proof solution to my problem?
Question: How can I display a specific text on each page printed by the browser, without it being saved in browser history?