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