I "borrowed" some code from the Khan Academy, which spits out a body tag with classes unique to IE versions.
<!--[if lt IE 7]> <body class="ie ie6 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 7]> <body class="ie ie7 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 8]> <body class="ie ie8 lte9 lte8"> <![endif]-->
<!--[if IE 9]> <body class="ie ie9 lte9"> <![endif]-->
<!--[if gt IE 9]> <body> <![endif]-->
<!--[if !IE]><!-->
<body>
<!--<![endif]-->
Thing is, when registering client scripts at the beginning of the body, Yii goes for the first body tag instead of the right body tag.
Yii::app()->clientScript->registerScript('myScript','// ...',CClientScript::POS_BEGIN)
Yields this in non-IE browsers:
<!--[if lt IE 7]> <body class="ie ie6 lte9 lte8 lte7"><script type="text/javascript">
/*<![CDATA[*/
// ...
/*]]>*/
</script>
<![endif]-->
<!--[if IE 7]> <body class="ie ie7 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 8]> <body class="ie ie8 lte9 lte8"> <![endif]-->
<!--[if IE 9]> <body class="ie ie9 lte9"> <![endif]-->
<!--[if gt IE 9]> <body> <![endif]-->
<!--[if !IE]><!-->
<body>
<!--<![endif]-->
My request is for having Yii detect the right body tag, since this would mean I would not need to grab an extension to address this issue.
alex-w
(Pr0j3ct A1ex)
October 18, 2012, 1:50pm
2
Can you not use a div wrapper with the ie class?
<body>
<div class="ie">
...
</div>
</body>
jacmoe
(Jacob Moena)
October 18, 2012, 8:30pm
3
Looks like a bug in Yii - could you perhaps create a ticket?
Yii shouldn’t grab a tag which is commented out.
mdomba
(Maurizio Domba Cerin)
October 19, 2012, 9:45am
4
Would there be the same problem even if the script would be inserted under the last body?
I mean, in your example above, the last <body> is inside an IF structure… so the scripts would be inserted inside that IF too, and would there be a problem with IE 7,8,9 as they would not use that IF at all?
abennouna
(Abennouna)
October 19, 2012, 11:07am
5
Interesting issue if I may say. But can you tell your use case? I can’t see a practical case of a script that should be registered in the beginning of the body, that can’t be registered in the head itself (ie POS_HEAD instead of POS_BEGIN).
softark
(Softark)
October 20, 2012, 12:48am
6
Using this trick, we could write IE specific hacks in CSS …
body {
...
}
body.ie6 {
...
}
body.ie7 {
...
}
But as Maurizio says, Yii can not tell which <body> will be adopted by the user browser …
So I think including an IE version specific css with this trick would be a decent solution.
<!--[if lt IE 7]> <link rel='stylesheet' type='text/css' href='ie6.css'> <![endif]-->
<!--[if IE 7]> <link rel='stylesheet' type='text/css' href='ie7.css'> <![endif]-->
<!--[if IE 8]> <link rel='stylesheet' type='text/css' href='ie8.css'> <![endif]-->
<!--[if IE 9]> <link rel='stylesheet' type='text/css' href='ie9.css'> <![endif]-->