如何获取client端屏幕分辨率?
要求:获得Client的屏幕宽度,值显示到一个Literal里面。
下面是我的代码,最后输出的是空,不知道是哪里的问题,应该怎么写
test2.aspx.cs
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; }}
<%@ 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>