开发者

Do conditional comments only work for stylesheets?

Do conditional comments only work for CSS styles and stylesheet links, or can they be applied to all HTML/JS. I'm asking because I'd like to display a specific message if the user is using a browser in which some functionality is known not to work/function as well as it could in others?

If not, is there anyway, via PHP + regex to get the exact browser that the user is using, as $_SERVER['HTTP_USER_AGENT'] seems to return a string containing several user agent na开发者_开发问答mes?


If you mean stuff like:

<!--[if lte IE 6]> ... <![endif]-->

yes, you can use this in HTML too (eg. it is often used to conditionally add some extra CSS for IE6 fixes).

But I wouldn't rely on this in order to, let's say, tell the user to upgrade the outdated browser. Instead, I would do that on the server-side by checking the $_SERVER['HTTP_USER_AGENT'].

The browser recognition isn't straight-forward since browsers tend to format the user-agent as they like; there are many libraries that use comparisons lists etc. in order to try figure out which actually is the browser/version/os by parsing the user-agent string.


conditional comments "work" in markup, you can wrap them around CSS, HTML and JavaScript. Just wrap whatever for non IE with [if !IE]

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜