In Google Chrome, Google Docs can control headers and footers from javascript. Does anybody know how this is achieved?

That’s basically it. Somehow, the javascript in Google Docs can turn off the default headers and footers showing the URL, date, page numbering, etc.

This only works in Google Chrome. When Google Docs is running from another browser it will print the headers/footers unless removed manually through the print configuration dialog. In Safari, it seems to generate a PDF server-side which of course will print outside of the browser.

  • JavaScript Popup Chrome 'save as'-deactivated? Why?
  • window.open height isn't the same in Google Chrome as other browsers
  • How to stop browser from scrolling when text is selected? Potential browser bug?
  • Why can't I see/debug javascript loaded with jquery.html() with Chrome
  • Is there an simulation of MozScrolledAreaChanged event in Chrome?
  • How to fix Native Host Has Exited error in Chrome browser extension — Native Messaging
  • I’ve searched around the web and have found nothing on how this is done. The javascript in the page is of course minified and obfuscated so it’s difficult to get any insights from there.

    So before I’m forced to dive into that spaghetti, I’d like to know if anybody has any ideas of how this is done.

  • Max size of location.hash in browser
  • Input text field auto-complete (auto-fill), doesn't work as expected on Chrome
  • Force Cache-Control: no-cache in Chrome via XMLHttpRequest on F5 reload
  • How are the attribute names on objects stored in Javascript?
  • Isotope blurred elements in google chrome
  • Service Worker throwing errors when fetching MP3 audio
  • One Solution collect form web for “In Google Chrome, Google Docs can control headers and footers from javascript. Does anybody know how this is achieved?”

    After delving into some source code I found on a web page that has also resolved the issue (not Google Docs), the secret is the following CSS:

    @page
    {
    margin:0;
    }
    

    This only works on Chrome, and perhaps Opera though I have to verify if the latter is true as it’s printing the background color by default while chrome prints with a white background and the colored background in my page might be just obscuring the header/footer text.

    Other browsers give differing results:

    • Firefox and Safari ignore the margins apparently and print the headers/footers anyway.
    • IE9 makes a mess of things and the contents print overlapped with the header/footer text. Poor browser always gets all the heat…

    In conclusion, combining this with silent printing coming out in Chrome 18 kiosk mode will make for some interesting functionality, such as mail merge capabilities right from the browser though I still have to research how secure kiosk mode is though, as navigating to a malicious page runs the risk of exhausting printer ink and paper.

    Navigation should be restricted to a URL white-list in this case.