javascript 使用window.print时如何通过css隐藏<A>标签的href属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17613273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide href attribute of <A> tag via css when using window.print
提问by user2548436
I've a php page, with a button that able the user to print via window.print function.
我有一个 php 页面,带有一个按钮,用户可以通过 window.print 函数进行打印。
I'd need to know how to hide the href attribute of an html tag when printing the page
我需要知道如何在打印页面时隐藏 html 标签的 href 属性
Example: if the tag is like follow:
示例:如果标签如下所示:
<a href='myurl.com'>HELLO</a>
I want to display just HELLO.
我只想显示 HELLO。
I've to do this only when i use window.print.
我只有在使用 window.print 时才需要这样做。
I've already set up the css for printing in this way:
我已经以这种方式设置了用于打印的 css:
@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 all works correctly, except for the link that was printed with the href part.
除了使用 href 部分打印的链接外,一切正常。
Thank you
谢谢
回答by user2548436
Thank you, the solution i've found that work form me is similar to your
谢谢,我发现我的工作形式与您的相似的解决方案
#section_to_print a[href]:after { display:none; }
In fact, the problem was generated by some css containing a rule like follow:
事实上,这个问题是由一些包含如下规则的 css 生成的:
a:link:after, a:visited:after {content:" (" attr(href) ")";font-size:90%;}
Like suggested at this link:
就像在此链接中建议的那样:
stackoverflow.com/questions/4834517/…
stackoverflow.com/questions/4834517/...
However, thank to much :) Regards
但是,非常感谢:) 问候
回答by TheScarecrow
why dont you use:
你为什么不使用:
#section_to_print a{
color:black;
text-decoration:none;
}