2

I have in my webpage, several anchors (i.e. <a name="my-magical-anchor"></a>) scattered along the page. I additionally have several links on my page which point to these anchors (i.e. <a href="#my-magical-anchor">Go to the Magical Anchor</a>). For when the page is printed, I was wondering if it would be possible to modify the text of the link, using CSS or JavaScript, to read something like Go to the Magical Anchor (page 12) to indicate the page number the reader should flip to in the printed document.

I would like to, if possible, not have to manually assign page breaks, but instead have my content flow across the pages and then update the link text before printing.

Thanks.

Maz
  • 3,375
  • 1
  • 22
  • 27
  • unless I misunderstand the question, why not have the text that you want on the screen as well? or at least have the text but hide it using CSS media queries. – akonsu Nov 20 '12 at 02:42
  • The problem is that I don't know what page number the anchor is on, since I don't want to have manual page breaks. – Maz Nov 20 '12 at 02:46

1 Answers1

2

Look at this article and go down to the section titled, "Cross-References": http://www.alistapart.com/articles/boom

The suggestion is to use target-counter, targeting the page counter, using the href attribute as the target link.

a.magical::after {
    content: "(page" target-counter(attr(href), page) ")"
}

The whole article is recommended too. Hat tip to Nathan Kot who linked to it.

Brian L
  • 3,201
  • 1
  • 15
  • 15
  • OHHHH nice nice, didn't actually read that part, but seems a lot nicer than my answer – Nathan Kot Nov 20 '12 at 02:53
  • 1
    As far as I can see, the techniques described in the article have not been implemented in browsers. They are however implemented in the Prince software mentioned, and it seems to do a nice job in converting HTML to PDF with (extended) CSS. The techniques have now been described (somewhat vaguely) in the Working Draft *CSS Generated Content for Paged Media Module* http://www.w3.org/TR/css3-gcpm/ – Jukka K. Korpela Nov 20 '12 at 06:19