4

Not referring to the URL at top of page.

When an <a> tag is printed in Chrome, it shows the URL after it.

Instead of just showing the anchor text (like this: StackOverflow)

It shows the anchor text w/ URL after it

(like this: StackOverflow (window.open('www.stackoverflow.com'))

This makes the printed page stretch off the printable area, and I'm trying to avoid this from happening. Can this setting be disabled somehow in printing mode or is there a @media print style that can be defined to remove this URL part from print screen?

Control Freak
  • 12,965
  • 30
  • 94
  • 145
  • May I ask, is that the javascript method of opening a new window rather than using `target="_blank"`? – MackieeE Aug 10 '14 at 09:58
  • i don't see that - perhaps its an option that you have. – Daniel A. White Aug 10 '14 at 09:58
  • 2
    possible duplicate of [Need to remove href values when printing in Chrome](http://stackoverflow.com/questions/7301989/need-to-remove-href-values-when-printing-in-chrome) – Daniel A. White Aug 10 '14 at 09:59
  • @MackieeE Yes, its to open a new window, but its only an example. There is much longer JS code in there that stretches off the page that needs to be removed. – Control Freak Aug 10 '14 at 09:59

2 Answers2

14

Tell it not to print anything after the anchor tag.

@media print {
    a:after { content:''; }
    a[href]:after { content: none !important; }

}
davidcondrey
  • 34,416
  • 17
  • 114
  • 136
  • Why does it need 2 CSS items? It seems 1st one will print empty string (nothing), which is effectively equal to 2nd one ... – Grace Jan 31 '23 at 08:47
  • 1
    the second definition is an override in case your using a framework such as Bootstrap which uses this selector. – davidcondrey Mar 16 '23 at 23:37
0

Simply use this,

<style type="text/css" media="print">
@page {
    size: auto;   /* auto is the initial value */
    margin: 0;  /* this affects the margin in the printer settings */
}
</style>
Sajjad Hossain
  • 185
  • 3
  • 14