Can I place conditional comments in the bottom of my html document? (in the body) or should it be in the head?

StackOverflow https://stackoverflow.com/questions/17175056

<script>if(BrowserDetect.browser=="safari"){document.write('<link rel="stylesheet" href="css/safari.css" type="text/css" media="all" />')}</script>

<!--[if lte IE 8]><link rel="stylesheet" type="text/css" href="css/pie.css" /><![endif]-->

Can I place conditional comments in the bottom of my html document? (in the body) or should it be in the head?

Placing those in the bottom is better in terms of page speed or not?

有帮助吗?

解决方案

You can have conditional comments anywhere. Only the specified version of IE will parse the contents. In this case, where you have CSS in your conditional comment, it should be in your <head>.

Also, it's not a good idea to use JS to insert a stylesheet. The user will see the unstyled (or incorrectly styled) content until the document.write fires, and the css file loads. Insert with a server-side script such as PHP first.

其他提示

If the line in question is the one you posted....

Then no, that has to go at the top of the page, as it is a CSS file, and will likely be needed to style the page....so you need to load it in the <head>

But to answer your actual question...conditional javasript logic can really go anywhere...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top