我的代码大概是这样的:
//客户端:jQuery(function($) {
var width = screen.width;
PageMethods.GetInfos(width ,onSuccess);
});//服务器端:[System.Web.Services.WebMethod]
public static string GetInfos(string width)
{
HttpContext.Current.Response.Cookies["StaticTestValuey"].Value = width;
return "";
}protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.Request.Cookies["StaticTestValuey"] != null)
{
string width = HttpContext.Current.Request.Cookies["StaticTestValuey"].Value;
BindData(width);
}
else
{
Label1.Text = "empty!";
}
}显然页面加载时,Page_Load会先执行,然后再GetInfos,请问大家,我的思路是不是错了,在页面加载时如何获取客户端的屏幕大小呢?(说明:我需要调用BindData(width);方法绑定数据,而不是使用GetInfos返回json)
//客户端:jQuery(function($) {
var width = screen.width;
PageMethods.GetInfos(width ,onSuccess);
});//服务器端:[System.Web.Services.WebMethod]
public static string GetInfos(string width)
{
HttpContext.Current.Response.Cookies["StaticTestValuey"].Value = width;
return "";
}protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.Request.Cookies["StaticTestValuey"] != null)
{
string width = HttpContext.Current.Request.Cookies["StaticTestValuey"].Value;
BindData(width);
}
else
{
Label1.Text = "empty!";
}
}显然页面加载时,Page_Load会先执行,然后再GetInfos,请问大家,我的思路是不是错了,在页面加载时如何获取客户端的屏幕大小呢?(说明:我需要调用BindData(width);方法绑定数据,而不是使用GetInfos返回json)
$(document).ready(function()
{
alert($(window).height()); //浏览器当前窗口可视区域高度
alert($(document).height()); //浏览器当前窗口文档的高度
alert($(document.body).height());//浏览器当前窗口文档body的高度
alert($(document.body).outerHeight(true));//浏览器当前窗口文档body的总高度 包括border padding margin alert($(window).width()); //浏览器当前窗口可视区域宽度
alert($(document).width());//浏览器当前窗口文档对象宽度
alert($(document.body).width());//浏览器当前窗口文档body的高度
alert($(document.body).outerWidth(true));//浏览器当前窗口文档body的总宽度 包括border padding margin
}
)
</script>
screen.height
System.Windows.Forms.Screen.Bounds.Width
System.Windows.Forms.Screen.Bounds.Height
JS就用
document.body.clientWidth
document.body.clientHeight
document.body.offsetWidth 等
document.body.clientHeight
document.body.offsetWidth
js 很好 也简单 或者用虎妞的也行
还是要建一个类库,调用System.Windows.Forms.Screen.Bounds.Width 返回值呢?
你直接用js的不行吗? 或者虎妞的jquery也行啊 !