Detecting resolution of client browser

  • Thread starter Thread starter Grzegorz Klimsa
  • Start date Start date
G

Grzegorz Klimsa

Hi !
I have a problem wiht detecting resolution of client web browser
I prepare several files of css style for different browsers and different
resolutions,
(such as : Style_1024x768.css ; Styleff_1024x768.css; Style_1280x1024.css ;
Styleff_1280x1024.css )

I want to set css style file depends on resolution browser

I wrote this script to detect type of browsers, but i don't have any idea
how to detect resolution ???

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<script runat="server">

protected void Page_Init(object sender, EventArgs e)
{
// Define an HtmlLink control.
string type = Request.Browser.Type;
HtmlLink myHtmlLink = new HtmlLink();

if (type == "IE7")
{

myHtmlLink.Href = "Style_1280x1024.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);
}
else
{
myHtmlLink.Href = "Styleff_10280x1024.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);
}

}

Greetings
Grzegorz
 
re:
!> I want to set css style file depends on resolution browser

There's many ways to do that.

This Google search will help you find one you can use/adapt :
http://www.google.com/search?hl=en&q=detect+browser+resolution

re:
!> if (type == "IE7")
{
!> myHtmlLink.Href = "Style_1280x1024.css";

That someone uses IE7 doesn't mean that their
screen resolution is necessarily set to 1280x1024.





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espanol : http://asp.net.do/foros/
======================================
 
Back
Top