Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Print a header with the page address (URL) in Safari Web Browsers
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, but sometimes not. Here is a tip to fill the gap:
  1. 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();
    }
  2. Open a new window (command-N) or a new tab (command-T) in Safari.
  3. Paste the text in the address field at the top of the window. Even if there are several lines, it will be OK.
  4. Drag and drop the URL symbol (the blue globe on the left of the address field) to the bookmarks bar.
  5. Give this bookmark a name in the pop-up dialog (e.g. Print URL Header). You now have a new "button" for this specific function.
  6. Click once to print the page.
  7. 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:
  • 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().
[robg adds: This hint originally appeared on Max_B's own tip page. I have modified it slightly (changed formatting and a word or two). Thanks for sharing, Max!]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[13,217 views]  

Print a header with the page address (URL) in Safari | 15 comments | Create New Account
Click here to return to the 'Print a header with the page address (URL) in Safari' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Print a header with the page address (URL) in Safari
Authored by: benfsmith on Feb 09, '05 02:38:16PM

Is there a way to have the date included as well? For sourcing sites, you often need both the url and the access date.



[ Reply to This | # ]
Print a header with the page address (URL) in Safari
Authored by: Jonsi on Feb 09, '05 05:35:32PM

Saft [http://haoli.dnsalias.com/Saft/] allows the printing of the title, URL and time as well as page numbers.



[ Reply to This | # ]
Print a header with the page address (URL) in Safari
Authored by: xandrar on Mar 27, '05 09:17:17PM

Thanks for saying that header can contain URL, date and pages -- but as I am new to Safari -- I don't know what to do with the information ou provided. Would you provide some guidance?

---
xandrar



[ Reply to This | # ]
Print the date too
Authored by: macsolve on Feb 10, '05 02:50:08AM
You can add the date simply like this:

entete.appendChild(document.createTextNode(document.URL+'%20%20'+Date()));


[ Reply to This | # ]
Print the date too
Authored by: youngjane1 on Apr 12, '05 07:59:24PM

Thank you for your answer, but I have no idea where to put this information you gave me! To put the date you say, simply add: entete: appendChild . . .
but where exactly does this go? HELP!!! I am a total novice!



[ Reply to This | # ]
Print the date too
Authored by: youngjane1 on Apr 18, '05 01:42:36PM

Can you please pass along specific instructions for adding a time/date stamp onto Safari web pages? I saw your post dated 2/9/05, but I have no idea what to do with the iformation you gave. Thank you!



[ Reply to This | # ]
Print a header with the page address (URL) in Safari
Authored by: cri on Feb 24, '05 03:17:17PM

For the date, you can add this line before the "document.body.insertBefore..." line

entete.appendChild(document.createTextNode(" "+Date()));



[ Reply to This | # ]
Print a header with the page address (URL) in Safari
Authored by: cri on Feb 24, '05 03:18:30PM

Doh...the other responses weren't coming up...guess that was redundant.



[ Reply to This | # ]
Print a header with the page address (URL) in Safari
Authored by: the_webmaestro on Feb 09, '05 03:04:46PM
You can also drag this above link to your button bar:

PrintURL

---
Father of Jeremy Logan

[ Reply to This | # ]

Print a header with the page address (URL) in Safari
Authored by: osxpounder on Feb 10, '05 03:36:21PM

Webmaestro, thanks for that link. Tested it; it works just fine for me and was so simple -- I just dragged your link to my button bar.

---
--
osxpounder



[ Reply to This | # ]
Button bar?
Authored by: Max_B on Feb 10, '05 06:39:30PM

Did I miss something or the "button bar" you are refering to is the one I called "bookmarks bar"?
If it's the true Button bar, where are standard "Previous", "Next".... buttons, I'm unable to replicate.
Max



[ Reply to This | # ]
Button bar?
Authored by: milo on Feb 11, '05 10:24:48AM

It is, in fact, the bookmarks bar.
Go to View -> Bookmarks Bar, or Command B to see it if it's not active.



[ Reply to This | # ]
Print a header with the page address (URL) in Safari
Authored by: adam93117 on May 26, '05 02:55:23PM

Thanks for the PrintURL button. This script works great!

I do notice though that urls will not wrap around if they are wider than the page. Is there a fix for this?

Thanks,
-Adam



[ Reply to This | # ]
Print a header with the page address (URL) in Safari
Authored by: ScottRussell2 on Aug 04, '05 04:08:10PM

You can also (at least in Safari 2.0) open ~/Library/Preferences/com.apple.safari.plist and toggle "PrintHeadersAndFooters" to "yes".

This prints the following:
upper left -- title of web page
upper right -- date/time stamp
lower left -- URL
lower right -- page x of y

---

Best wishes,
Scott
--
Scott Russell

IT Support Engineer, Office of Information Technologies, University of Notre Dame
Instructor of Horn, University o



[ Reply to This | # ]
Print a header with the page address (URL) in Safari
Authored by: sjk on Aug 05, '05 06:37:44PM

Isn't that the same as enabling "Print webpage information in headers and footers" under the Safari item of the bottom print dialog menu (the one that defaults to "Copies & Pages")?

It would be useful if the Safari settings (backgrounds & webpage info) were preserved in Presets so you could easily toggle them by selecting a preset but unfortunately those settings aren't inherited by saved presets.



[ Reply to This | # ]