Safari : how to print a header with the page address (URL)
Default printing in Safari does not add a header with the page address (URL), as do other browsers.
This is OK for me, most of the time, sometimes not.
Here is a tip to fill the gap.
Installation, short version:
- Drag the following link to the bookmarks bar od Fafari : Impression URL
Note : the bookmarks bar is displayed by default. If it's not the case select it in the View menu.
Installation in details:
- Select and copy the following code:
javascript:
if (document.body.firstChild.id == 'print_URL_header') {
document.body.removeChild(document.body.firstChild);
} else {
entete = document.createElement('pre');
entete.setAttribute('id','print_URL_header');
entete.appendChild(document.createTextNode(document.URL));
document.body.insertBefore(entete, document.body.firstChild, null);
window.print();
}
- Open a new window (command-N) or a new tab (command-T) in Safari.
- Paste the text in the address field at the top of the window. Even if there are several lines, it will be OK.
- Drag & drop the URL symbol (the blue globe on the left of the address field) to the bookmarks bar.
- Give this bookmark a name in the pop-up dialog (e.g. print URL header).
Usage
You got a new "button" for this specific function.
- Click once to print the page.
- Click a second time to clean up the added header from the displayed page.
You can move this bookmark as you like, as with any bookmark.
Remarks
- To print the date along with URL, replace the line
entete.appendChild(document.createTextNode(document.URL));
entete.appendChild(document.createTextNode(Date()+' - '+document.URL));
- The two-click procedure is due to asynchronous print processing. Too bad!
- The header is only printed on the first page. To define a global header implies using a specific CSS stylesheet.
- I tried very hard to achieve the same feature using the default stylesheet of Safari, but could not find the way to acces URL from the CSS code.
- The "print button" tip is borrowed from someone on the net. It was a standard print using javascript:window.print().