使用 CSS 规则的文件类型图标
我正在使用 这种方法在我的网络应用程序中的文件的每个链接附近显示一个图标。
为了避免 IE 历史缓存问题,我将链接显示为
<a href="path/to/the/file.xls?timestamp=0234562">FileName.xls</a>
.
In this case the css rule doesn't do his job.你知道我该如何解决这个问题吗?
I'm using this approach to display an icon near each link to a file from my web-application.
In order to avoid IE history cache problems I display a link as
<a href="path/to/the/file.xls?timestamp=0234562">FileName.xls</a>
.
In this case the css rule doesn't do his job.
Do you know how can I solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能使用的选择器
a[href$='.xls']
仅当它与 HREF 值的末尾匹配时才适用。 请改用a[href*=.xls]
。摘自选择器级别 3:
编辑
如果您可以控制 .htaccess 文件,则可以确保避免出现缓存问题,以便可以使用原始样式表规则。 请参阅使用 Apache 和 .htaccess 的缓存控制标头了解更多信息细节。
The selector
a[href$='.xls']
you probably use, applies only if it matches the end of HREF's value. Usea[href*=.xls]
instead.Excerpt from Selectors Level 3:
Edit
If you have control over the .htaccess file, you may ensure there to avoid cache problems, so you can use your original stylesheet rules. See Cache-Control Headers using Apache and .htaccess for further details.
问题是
a[href$='.xls']
与锚点的href
属性的末尾匹配,但您要附加时间戳,因此结尾该 href 实际上是时间戳。为了避免缓存问题,您可以使用代理来处理下载; 也就是说,使用触发文件下载的脚本。 在 PHP 中,它很容易通过 readfile() 函数并发送无缓存标头来实现,例如:
但由于我不知道您使用的是哪种编程语言,所以我不能说太多。
The problem is that
a[href$='.xls']
matches the end of thehref
attribute of your anchor, but you're appending the timestamp, so the ending of that href is actually the timestamp.To avoid caching problems you could handle the downloads using a proxy; that is, use a script that triggers the download of files. In PHP it's easily accomplised with readfile() function and sending no-cache headers, for example:
But since I don't know which programming language you're using, I couldn't say much more.
邓肯,我知道这个问题已经得到了回答,但为了您的评论,这里有一个应该适合您的功能。 我认为它几乎直接来自 PHP 手册或其他地方的示例。 我在一个类中处理其他事情,例如检查文件权限、上传等。根据您的需要进行修改。
Duncan, I know this has already been answered, but just for your comment, here is a function that should work for you. I think it is almost straight off the PHP manual or some other example(s) somewhere. I have this in a class that handles other things like checking file permissions, uploads, etc. Modify to your needs.