Yii Framework Forum: Detection Of Real <Body> In Conditional Comments - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Detection Of Real <Body> In Conditional Comments Rate Topic: -----

#1 User is offline   Sage Gerard 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 04-July 12

Posted 13 October 2012 - 12:58 PM

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.
0

#2 User is offline   alex-w 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 223
  • Joined: 25-November 10

Posted 18 October 2012 - 08:50 AM

Can you not use a div wrapper with the ie class?
<body>
  <div class="ie">
    ...
  </div>
</body>

0

#3 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 18 October 2012 - 03:30 PM

Looks like a bug in Yii - could you perhaps create a ticket? :)

Yii shouldn't grab a tag which is commented out.
"Less noise - more signal"
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 19 October 2012 - 04:45 AM

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?
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,166
  • Joined: 05-January 12
  • Location:Morocco

Posted 19 October 2012 - 06:07 AM

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).
0

#6 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,082
  • Joined: 16-February 11
  • Location:Japan

Posted 19 October 2012 - 07:48 PM

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]-->

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users