+1-888-365-2779
Try Now
More in this section

Forums / Designing with Sitefinity / detecting screen resolutions in sitefinity

detecting screen resolutions in sitefinity

2 posts, 0 answered
  1. Jome Akpoduado
    Jome Akpoduado avatar
    16 posts
    Registered:
    07 Jan 2010
    16 Feb 2010
    Link to this post
    Hi guys,
    is it possible to detect the screen resolution of a client and adjusting the use of appropriate css files accordingly. How would I go about this if it is?

    Many thanks

    Jome.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Feb 2010
    Link to this post
    Hello Jome Akpoduado,

    Below is a sample code that illustrates how to detect the screen resolution

    <script language="javascript">
        $(document).ready(function() {
            res = "Screen Resolution is: " + screen.width + "x" + screen.height;
            alert(res);
            if ((screen.width >= 1024) && (screen.height >= 768)) {
                window.location = "http://www.telerik.com";
            }
            else {
                window.location = "http://www.sitefinity.com";
            }
     
        });
    </script>

    You can register the script on the serve by using Page.ClientScript.RegisterStartupScript(this.GetType(), "SomeKey", checkres); and then before the page renders you can add the needed stylesheets to the page header (Page.Header.Controls.Add( control );)

    protected void Page_Init(object sender, EventArgs e)
    {
      HtmlLink myHtmlLink = new HtmlLink();
      myHtmlLink.Href = "~/StyleSheet.css";
      myHtmlLink.Attributes.Add("rel", "stylesheet");
      myHtmlLink.Attributes.Add("type", "text/css");
     
      // Add the HtmlLink to the Head section of the page.
      Page.Header.Controls.Add(myHtmlLink);
     
    }


    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
2 posts, 0 answered