How to programmatically remove headers and footers in print pages on Safari with JavaScript?

55 views Asked by At

I am having trouble removing the header and footer from print pages in Safari using JavaScript. While I know that in most browsers, the header and footer can be manually disabled through the user's print settings, my goal is to automate this process with code so that users do not see the headers and footers when printing web page content.

enter image description here

Does anyone know how to accomplish this programmatically in Safari? Or is there an alternative way to circumvent the default print settings in Safari?

Thank you!

my goal is to automate this process with code so that users do not see the headers and footers when printing web page content.

1

There are 1 answers

1
Tolgahan Dayanıklı On BEST ANSWER

As far as I know, there is no straightforward way to remove those two options from the print screen with JavaScript. Safari does not provide a direct API for manipulating those print settings like some other browsers do. However, you can try the following to exclude the footer and the header during the print state:

@media print {
    @page {
        margin: 0;
    }
    body {
        margin: 0;
    }
    header, footer {
        display: none !important;
    }
}