2011-09-06 47 views

回答

2

您可以使用CSS浏览器选择器。网上有不同的解决方案。

例如:

CSS Browser Selector

CSS的浏览器选择器是一个小型的JavaScript库,它允许你包括每个浏览器不同的层叠样式表(CSS)。

一个例子:

<style type="text/css"> 
.ie .example { 
    background-color: yellow 
} 
.ie7 .example { 
    background-color: orange 
} 
.opera .example { 
    background-color: green 
} 
.webkit .example { 
    background-color: black 
</style> 

如果谷歌为“每个浏览器不同的CSS”,你会发现其他的解决方案,以及,但大多归结为类似的解决方案。

另一种方法是检测ASP.NET中的浏览器类型和功能,以便可以呈现适当的HTML/CSS/...等。你可以找到更多信息,关于这个问题在这里:

http://msdn.microsoft.com/en-us/library/3yekbd5b.aspx

例如:

private void Button1_Click(object sender, System.EventArgs e) 
{ 
    System.Web.HttpBrowserCapabilities browser = Request.Browser; 
    string s = "Browser Capabilities\n" 
     + "Type = "     + browser.Type + "\n" 
     + "Name = "     + browser.Browser + "\n" 
     + "Version = "     + browser.Version + "\n" 
     + "Major Version = "   + browser.MajorVersion + "\n" 
     + "Minor Version = "   + browser.MinorVersion + "\n" 
     + "Platform = "    + browser.Platform; 

    TextBox1.Text = s; 
} 

请求的浏览器属性返回的HttpBrowserCapabilities对象。它包含有关客户端上运行的浏览器功能的信息。

http://msdn.microsoft.com/en-us/library/system.web.httpbrowsercapabilities.aspx

0

使用使用Request.Browser可以判断浏览器用户正在使用您的

2

您可以检查Request对象的UserAgent财产。

页头标签

<%# Request.UserAgent.ToLower().Contains("safari") ? 
    "<link rel='stylesheet' type='text/css' href='safari.css' />" : 
    "<link rel='stylesheet' type='text/css' href='other.css' />" %> 
2

使用下里面的东西....在你的控制......,你可以设置不同的风格......为不同的浏览器asp.net文本框控件。

<asp:TextBox ID="TestTextBox" runat="server" ie:Text="You are in Internet explorer." mozilla:Text="You are in Firefox." Text="You are in other browser." ie:CssClass="IEStyle" mozilla:CssClass="FFStyle" CssClass="DefaultStyle" /> 
+0

看看这个..东西....这是非常新的... – sikender

0

您可以从JavaScript像检查:

if (navigator.appName == 'Microsoft Internet Explorer') { 
       var fileref = document.createElement("link") 
       fileref.setAttribute("rel", "stylesheet") 
       fileref.setAttribute("type", "text/css") 
       fileref.setAttribute("href", filename) 
      } 
相关问题