日期:2014-05-17  浏览次数:20827 次

如何获取client端屏幕分辨率?
要求:获得Client的屏幕宽度,值显示到一个Literal里面。
下面是我的代码,最后输出的是空,不知道是哪里的问题,应该怎么写

test2.aspx.cs
C# code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class test2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {        
        Literal1.Text = this.mydata.Value;
    }
}


test2.aspx
HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test2.aspx.cs" Inherits="test2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">  
    <input type="hidden" id="mydata" runat="server" /> 
    <script type="text/javascript">
      function   LoadSys()   
      {    
        document.getElementById("mydata").value = screen.availWidth;        
      }   
      LoadSys();
    </script>  

        <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    </form>
</body>
</html>


------解决方案--------------------
取Client端最好用js

screen.width
screen.height
screen.availWidth
screen.availHeight

后面两个是去掉状态栏的高度或宽度,取屏幕的可用宽度或高度。
------解决方案--------------------
路过学习了