How Can I Add a Body Class in Magento Go When the Browser is IE8? [closed]
-
16-10-2019 - |
سؤال
I am using the following Custom Layout Update XML in Magento Go to add a body class if the browser is IE8. Currently this code adds the class for every browser instead of only IE8. How can I write this so it only adds the class for IE8?
<reference name="root">
<action method="addBodyClass">
<classname>ie8</classname>
<if>IE 8</if>
</action>
</reference>
المحلول
[Edit]
Add the js below in the footer. and it should work.
if (navigator.appName == "Microsoft Internet Explorer") {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");
//If the regEx through the userAgent is not null
ieVersion = -1;
if (re.exec(ua) != null) {
//Set the IE version
ieVersion = parseInt(RegExp.$1);
}
if (ieVersion == 8){
$$('body')[0].addClassName('ie8');
}
}
I don't have experience with Magento GO but if it's similar to CE or EE you should have a textarea in the config panel where you can add miscellaneous javascript.
[OLD answer for Magento CE or EE]
What you are trying won't work. The addBodyClass
meyhod acceps only one paramerter... the class name.
What you can do is to create a js file with this content:
document.observe("dom:loaded", function() {
$$('body')[0].addClassName('ie8');
});
Let's call this file 'ie8.js' and place it in the js folder. Now in your layout file add this:
<default>
<reference name="head">
<action method="addItem">
<type>js</type>
<name>ie8.js</name>
<params/><if>IE 8</if>
</action>
</reference>
</default>
Clear the cache and give it a go.