How do I hide an element when printing a web page?

前端 未结 10 1157
-上瘾入骨i
-上瘾入骨i 2020-11-22 03:34

I have a link on my webpage to print the webpage. However, the link is also visible in the printout itself.

Is there javascript or HTML code which would hide the lin

10条回答
  •  一个人的身影
    2020-11-22 04:20

    You could place the link within a div, then use JavaScript on the anchor tag to hide the div when clicked. Example (not tested, may need to be tweaked but you get the idea):

    
    

    The downside is that once clicked, the button disappears and they lose that option on the page (there's always Ctrl+P though).

    The better solution would be to create a print stylesheet and within that stylesheet specify the hidden status of the printOption ID (or whatever you call it). You can do this in the head section of the HTML and specify a second stylesheet with a media attribute.

提交回复
热议问题