开发者

CSS: check if href is a file?

开发者 https://www.devze.com 2023-01-15 02:54 出处:网络
I know I can use a[href$=\'.mov\'] to check if 开发者_如何学运维the href refers to a .mov 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

精彩评论

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