Tuesday, July 30, 2013

Change the header color of form using Javascript.

InjectHeaderCSS("00C78C","F6F8FA");

function InjectHeaderCSS(startColor, endColor) {

var headerCSSIE9 = ".ms-crm-Form-HeaderContainer{ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#" + startColor + ", endColorstr=#" + endColor + "); }";
var headerCSSIE10 = ".ms-crm-Form-HeaderContainer{background: -ms-linear-gradient(top,  #2989d8 0%,#" + startColor + " 0%,#F6F8FA 100%,#" + endColor + " 100%);}";

var headerchrome = ".ms-crm-Form-HeaderContainer{background: -webkit-linear-gradient(top,  #2989d8 0%,#" + startColor + " 0%,#F6F8FA 100%,#" + endColor + " 100%);}"

var head = document.getElementsByTagName('head')[0];
var styleElement = document.createElement('style');
styleElement.setAttribute('type', 'text/css');
if (styleElement.styleSheet) {
    if (Mscrm.Utilities.isIE9()) {
        styleElement.styleSheet.cssText = headerCSSIE9;
    } else if (Mscrm.Utilities.isIE10()) {
        styleElement.styleSheet.cssText = headerCSSIE10;
    } else if (Mscrm.Utilities.isChrome()) {
        styleElement.styleSheet.cssText = headerchrome;
    } else {
        styleElement.styleSheet.cssText = headerCSSIE9;
    }
}
else {

    if (Mscrm.Utilities.isIE9()) {
        styleElement.appendChild(document.createTextNode(headerCSSIE9));
    } else if (Mscrm.Utilities.isIE10()) {
        styleElement.appendChild(document.createTextNode(headerCSSIE10));
    } else if (Mscrm.Utilities.isChrome()) {
        styleElement.appendChild(document.createTextNode(headerchrome));
    } else {
        styleElement.appendChild(document.createTextNode(headerCSSIE9));
    }
}
head.appendChild(styleElement);

 }

No comments:

Post a Comment