How to hide href attribute of <a> tag via css when using window.print

I have a php page with a button that allows the user to print through the window.print function.

I need to know how to hide the href attribute of an html tag when printing a page

Example: if the tag looks like this:

<a href='myurl.com'>HELLO</a> 

I want to show only HELLO.

I have to do this only when I use window.print.

I already installed css for printing as follows:

 @media print { body * { visibility:hidden; } #section_to_print, #section_to_print * { visibility:visible; } #section_to_print { position:absolute; left:0; top:0; } /* //HERE I NEED A RULE TO HIDE // ONLY HREF ATTRIBUTE BUT NOT CONTENT OF A TAG //BUT IN THIS WAY THEY HIDE THE WHOLE TAG OF COURSE #section_to_print a { display:none; } */ @page { size: landscape; } } 

And everything works correctly, except for the link that was printed using the href part.

Thanks Francesco

+4
source share
2 answers

Thank you, the solution that I found that the form of work me is similar to yours

  #section_to_print a[href]:after { display:none; } 

Actually the problem was generated by some css containing a rule like the following:

  a:link:after, a:visited:after {content:" (" attr(href) ")";font-size:90%;} 

As suggested by this link:

stackoverflow.com/questions/4834517 / ...

However, thanks a lot :) Regards, Francesco

+14
source

why you are not using:

 #section_to_print a{ color:black; text-decoration:none; } 
-2
source

Source: https://habr.com/ru/post/1491097/


All Articles