开发者

CSS: check if href is a file?

I know I can use

a[href$='.mov'] 

to check if 开发者_如何学运维the href refers to a .mov file.

However, can I generally check if the href attribute refers to a file? So any file with a suffix at the end?


You can't tell from URL, and also the definition of a file is subjective. Technically, index.html is a file, but probably not a file from the prospective of your question.

If you had a list of known file extensions you wanted to select, you could do something like this

a[href$='.mov'],
a[href$='.exe'] {
    color: red;
} 

Otherwise if you had a server side language, you could follow the links and look for download response headers (look for Content-Disposition: inline) though this is also probably way too much overhead and a bad idea.

I don't think the look for any link with extension is a good idea to determine if it links to a file. You probably want a whitelist, and check against that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜