用Ajax读取不同浏览器信息以及所打开浏览器的尺寸
2008-03-12 17:49
483 查看
用JavaScript读取当前所用到的浏览器的信息(包括IE,Firefox,Safari,Opera等),并且读取当前所打开浏览器的尺寸。
<%@ Page Language="C#" %>
<!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>Get Client Bound By Brower Type</title>
</head>
<body style="font-family:Verdana; font-size: 15px;">
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1" />
<script language="javascript" type="text/javascript">
document.write(window.navigator.userAgent);
</script>
<hr />
<script language="javascript" type="text/javascript">
document.write("Browser agent" + Sys.Browser.agent.toString() +"<br />");
document.write("Has Debugger Statement: " + Sys.Browser.hasDebuggerStatement + "<br />");
document.write("Name: " + Sys.Browser.name + "<br />");
document.write("Version: " + Sys.Browser.version);
</script>
<script language="javascript" type="text/javascript">
function getClientBounds()
{
var clientWidth;
var clientHeight;
switch (Sys.Browser.agent)
{
case Sys.Browser.InternetExplorer:
clientWidth = document.compatMode == "CSS1Compat" ?
document.documentElement.clientWidth : document.body.clientWidth;
clientHeight = document.compatMode == "CSS1Compat" ?
document.documentElement.clientHeight : document.body.clientHeight;
break;
case Sys.Browser.Safari:
clientWidth = window.innerWidth;
clientHeight = window.innerHeight;
break;
case Sys.Browser.Opera:
clientWidth = Math.min(window.innerWidth, document.body.clientWidth);
clientHeight = Math.min(window.innerHeight, document.body.clientHeight);
break;
default: // FireFox, etc.
clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
break;
}
return {width: clientWidth, height: clientHeight};
}
</script>
<hr />
<div id="clientBounds"></div>
<script language="javascript" type="text/javascript">
window.onresize = function()
{
var bounds = getClientBounds();
$get("clientBounds").innerHTML =
String.format("Width: {0}, Height: {1}",
bounds.width, bounds.height);
}
</script>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!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>Get Client Bound By Brower Type</title>
</head>
<body style="font-family:Verdana; font-size: 15px;">
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1" />
<script language="javascript" type="text/javascript">
document.write(window.navigator.userAgent);
</script>
<hr />
<script language="javascript" type="text/javascript">
document.write("Browser agent" + Sys.Browser.agent.toString() +"<br />");
document.write("Has Debugger Statement: " + Sys.Browser.hasDebuggerStatement + "<br />");
document.write("Name: " + Sys.Browser.name + "<br />");
document.write("Version: " + Sys.Browser.version);
</script>
<script language="javascript" type="text/javascript">
function getClientBounds()
{
var clientWidth;
var clientHeight;
switch (Sys.Browser.agent)
{
case Sys.Browser.InternetExplorer:
clientWidth = document.compatMode == "CSS1Compat" ?
document.documentElement.clientWidth : document.body.clientWidth;
clientHeight = document.compatMode == "CSS1Compat" ?
document.documentElement.clientHeight : document.body.clientHeight;
break;
case Sys.Browser.Safari:
clientWidth = window.innerWidth;
clientHeight = window.innerHeight;
break;
case Sys.Browser.Opera:
clientWidth = Math.min(window.innerWidth, document.body.clientWidth);
clientHeight = Math.min(window.innerHeight, document.body.clientHeight);
break;
default: // FireFox, etc.
clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
break;
}
return {width: clientWidth, height: clientHeight};
}
</script>
<hr />
<div id="clientBounds"></div>
<script language="javascript" type="text/javascript">
window.onresize = function()
{
var bounds = getClientBounds();
$get("clientBounds").innerHTML =
String.format("Width: {0}, Height: {1}",
bounds.width, bounds.height);
}
</script>
</form>
</body>
</html>
相关文章推荐
- 浏览器打开ajax接受到的html 文本信息
- Ajax提交打开新窗口,浏览器拦截处理;以及跨域问题
- AJAX在不同浏览器中XMLHttpRequest对象的生成示例
- 获取不同规则屛参中屏幕尺寸信息
- UITableViewCell中设置不同图片尺寸相同以及设置图片为圆形的方法
- php+ajax 实现输入读取数据库显示匹配信息
- python pickle模块使用-将内存数据保存到文本中以及从文本中直接读取信息到内存中
- 用Ajax发请求,然后在服务器端重定向(不能达到期望的结果) 与 用浏览器直接向服务器重定向 是不同的
- 检测浏览器是否开启firebug以及如何避免调试信息带来的脚本错误
- 解释一下你对盒模型的理解,以及如何在 CSS 中告诉浏览器使用不同的盒模型来渲染你的布局。
- 解释一下你对盒模型的理解,以及如何在 CSS 中告诉浏览器使用不同的盒模型来渲染你的布局。
- python 的 IDLE 无法连接以及 jupyter notebook 无法打开浏览器
- C# 打开浏览器并 POST 提交信息
- python 与 webdriver结合打开不同浏览器
- 长连接的定义及其优缺点,以及在不同的浏览器中的支持情况
- 以Base64字符串形式上传文件——在web浏览器端使用原生Javascript及Ajax读取本地文件并发送请求到服务器
- Excel关闭或者打开时,QTP读取Excel内容的不同结果
- 不同内核浏览器的差异以及浏览器渲染简介(转)
- 不同内核浏览器的差异以及浏览器渲染简介
- 关闭浏览器再打开,网站是否应该自动登录以及如何实现呢?