Wednesday 11 April 2012

How to provide IE 7.0 Compatibility viewfrom IE8.0 in .NET?

IE Compatibility View


You can add the meta tag in the OnInit event of the page as shown in the below code:

protected override void OnInit(EventArgs e){    //Always do the check before adding the meta tag    if (CheckBrowser("IE", 8))    {        HtmlMeta meta = new HtmlMeta();
        meta.HttpEquiv = "X-UA-Compatible";        meta.Content = "IE=EmulateIE7";
        this.Page.Header.Controls.AddAt(0, meta);    }}
/// <summary>/// Checks the browser./// </summary>/// <param name="browserName">Name of the browser.</param>/// <param name="browserMajorVersion">The browser major version.</param>/// <returns></returns>public static bool CheckBrowser(string browserName, int browserMajorVersion){    HttpBrowserCapabilities br = HttpContext.Current.Request.Browser;
    if (br.Browser.ToUpper().Equals(browserName) && (br.MajorVersion == browserMajorVersion))        return true;    else        return false;}




No comments:

Post a Comment