By design, you can't touch the browser print dialog.
When you use the @page{ margin: 8mm}
you make the default page margin smaller, and all the extra details are gone because they have no place to be.
Because both the page number and the page url are in the bottom of the page- you can't show or hide only one of them, but,you can change the page URL before the print dialog is shown, and change it back when the print is over, so the printed page won't reveal URL structure.
//custom function to fire when print dialog is closed
function afterPrintOver (){
console.log('Print is over.');
//remove our empty state
window.history.back();
}
//detect when the user is click `Ctrl + P` to print
document.addEventListener('keydown', function(e){
const PKeyCode = 80;
if( e.ctrlKey && e.keyCode === PKeyCode ){
//stop the browser from open the print dialog
event.preventDefault();
//add an empty state, the url now will be www.yourDomainName.com/#/print
window.history.pushState('', '', '#/print');
//call our afterPrintOver function, and 'pass' the result of `window.print()`*
afterPrintOver(window.print());
});
This is whats happen:
- The user press CTRL + P
- We add an empty state to the history with custom relative url
- The browser's print dialog show the custom url
- The print is over (or, the user close the print dialog)
- We remove the empty state, that will change the url back to the correct url
*The trick is that our afterPrintOver
function won't be fire until the window.print()
function will over and return undefined
, which means, the print process is over.