Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

like image 942
Sebastian Ferreyra Avatar asked Mar 12 '12 18:03

Sebastian Ferreyra


1 Answers

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.

like image 62
Sebastian Ferreyra Avatar answered Sep 27 '22 18:09

Sebastian Ferreyra