window.screen 对象
不带 window 前缀也可以写:
screen 对象包含用户屏幕的信息。
属性:
screen.width:属性返回以像素计的访问者屏幕宽度
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"屏幕宽度是:" + screen.width;
</script>
screen.height:属性返回以像素计的访问者屏幕的高度。
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"屏幕高度是:" + screen.height;
</script>
screen.availWidth:可用宽度,属性返回访问者屏幕的宽度,以像素计,减去诸如窗口工具条之类的界面特征
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"可用屏幕宽度是:" + screen.availWidth;
</script>
screen.availHeight:可用高度,属性返回访问者屏幕的高度,以像素计,减去诸如窗口工具条之类的界面特征。
screen.colorDepth:属性返回用于显示一种颜色的比特数。
screen.pixelDepth: 属性返回屏幕的像素深度。
window.location 对象可用于获取当前页面地址(URL)并把浏览器重定向到新页面。
window.location 对象
可不带 window 前缀书写。
window.location.href 返回当前页面的 href (URL)
window.location.hostname 返回 web 主机的域名
window.location.pathname 返回当前页面的路径或文件名
window.location.protocol 返回使用的 web 协议(http: 或 https:)
window.location.assign 加载新文档
window.location.port 返回当前页面的端口,如果页面使用的是默认端口(http:80,https:443),则大多数浏览器会显示为0或者不显示
window.location.assign(url) : 加载 URL 指定的新的 HTML 文档。 就相当于一个链接,跳转到指定的url,当前页面会转为新页面内容,可以点击后退返回上一个页面。
window.location.replace(url) : 通过加载 URL 指定的文档来替换当前文档 ,这个方法是替换当前窗口页面,前后两个页面共用一个窗口,所以是没有后退返回上一页的
window.history 对象
可不带 window 书写。
为了保护用户的隐私,JavaScript 访问此对象存在限制。
length属性:浏览器历史列表中的 URL数量
方法:
history.back() - 方法加载历史列表中前一个 URL。
这等同于在浏览器中点击后退按钮
<script>
function goBack() {
window.history.back()
}
</script>
</head>
<body>
<input type="button" value="Back" onclick="goBack()">
</body>
history.forward() - 方法加载历史列表中下一个 URL。
这等同于在浏览器中点击前进按钮。
<script>
function goForward() {
window.history.forward()
}
</script>
</head>
<body>
<input type="button" value="Forward" onclick="goForward()">
</body>
go(num),根据num值前进或者后退,例如go(-2),后退两步
num为0则为重新刷新,正数为前进,负数则为后退
window Navigator对象
在编写时可不使用 window 这个前缀。
对象包含有关访问者浏览器的信息。
<div id="example"></div>
<script>
txt = "<p>浏览器代号: " + navigator.appCodeName + "</p>";
txt+= "<p>浏览器名称: " + navigator.appName + "</p>";
txt+= "<p>浏览器版本: " + navigator.appVersion + "</p>";
txt+= "<p>启用Cookies: " + navigator.cookieEnabled + "</p>";
txt+= "<p>硬件平台: " + navigator.platform + "</p>";
txt+= "<p>用户代理: " + navigator.userAgent + "</p>";
txt+= "<p>用户代理语言: " + navigator.language + "</p>";
</script>
appCodeName 属性返回浏览器的应用程序代码名称
appName 属性返回浏览器的应用程序名称
appVersion 属性返回有关浏览器的版本信息
cookieEnabled 属性返回 true,如果 cookie 已启用,否则返回 false
platform 属性返回浏览器平台(操作系统)
userAgent 属性返回由浏览器发送到服务器的用户代理报头(user-agent header)
language 属性返回浏览器语言
product 属性返回浏览器引擎的产品名称: