JavaScript -- 时光流逝(十):Screen 对象、History 对象、Location 对象
JavaScript -- 知识点回顾篇(十):Screen 对象、History 对象、Location 对象
1. Screen 对象
1.1 Screen 对象的属性
(1) availHeight: 返回屏幕的高度(不包括Windows任务栏)
(2) availWidth: 返回屏幕的宽度(不包括Windows任务栏)
(3) colorDepth: 返回目标设备或缓冲器上的调色板的比特深度
(4) height: 返回屏幕的总高度
(5) pixelDepth: 返回屏幕的颜色分辨率(每像素的位数)
(6) width: 返回屏幕的总宽度
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript">
document.write("可用高度: " + screen.availHeight);
document.write("<br/>可用宽度: " + screen.availWidth);
document.write("<br/>颜色深度: " + screen.colorDepth);
document.write("<br/>总高度: " + screen.height);
document.write("<br/>总宽度: " + screen.width);
document.write("<br/>颜色分辨率: " + screen.pixelDepth);
</script>
</head>
<body>
</body>
</html>

2. History 对象
2.1 History 对象的属性
(1) length: 返回历史列表中的网址数
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript">
document.write("历史列表中URL的数量: " + history.length);
</script>
</head>
<body>
</body>
</html>

2.2 History 对象的方法
(1) back(): 加载 history 列表中的前一个 URL
(2) forward(): 加载 history 列表中的下一个 URL
(3) go(): 加载 history 列表中的某个具体页面
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript">
function my_back(){
window.history.back()
}
function my_forward(){
window.history.forward()
}
function my_go(){
window.history.go(-2)
}
</script>
</head>
<body>
<input type="button" value="back()方法" onclick="my_back()">
<input type="button" value="forward()方法" onclick="my_forward()">
<input type="button" value="go()方法" onclick="my_go()">
</body>
</html>
3. Location 对象
3.1 Location 对象的属性
(1) hash: 返回一个URL的锚部分
(2) host: 返回一个URL的主机名和端口
(3) hostname: 返回URL的主机名
(4) href: 返回完整的URL
(5) pathname: 返回的URL路径名。
(6) port: 返回一个URL服务器使用的端口号
(7) protocol: 返回一个URL协议
(8) search: 返回一个URL的查询部分
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript">
document.write(location.hash);
document.write('<br/>'+location.host);
document.write('<br/>'+location.hostname);
document.write('<br/>'+location.href);
document.write('<br/>'+location.pathname);
document.write('<br/>'+location.port);
document.write('<br/>'+location.protocol);
document.write('<br/>'+location.search);
</script>
</head>
<body>
</body>
</html>
3.2 Location 对象的方法
(1) assign(): 载入一个新的文档
(2) reload(): 重新载入当前文档
(3) replace(): 用新的文档替换当前文档
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript">
function my_assign(){
window.location.assign("https://www.baidu.com")
}
function my_reload(){
location.reload()
}
function my_replace(){
window.location.replace("https://www.hao123.com")
}
</script>
</head>
<body>
<input type="button" value="assign()方法" onclick="my_assign()">
<input type="button" value="reload()方法" onclick="my_reload()">
<input type="button" value="replace()方法" onclick="my_replace()">
</body>
</html>
JavaScript -- 时光流逝(十):Screen 对象、History 对象、Location 对象的更多相关文章
- JavaScript -- 时光流逝(十三):DOM -- Console 对象
JavaScript -- 知识点回顾篇(十三):DOM -- Console 对象 (1) assert() : 如果断言为 false,则在信息到控制台输出错误信息.(2) clear() : 清 ...
- JavaScript -- 时光流逝(十一):DOM -- Document 对象
JavaScript -- 知识点回顾篇(十一):DOM -- Document 对象 (1) document.activeElement: 返回文档中当前获得焦点的元素. <!doctype ...
- JavaScript -- 时光流逝(十二):DOM -- Element 对象
JavaScript -- 知识点回顾篇(十二):DOM -- Element 对象 (1) element.accessKey: 设置或返回accesskey一个元素,使用 Alt + 指定快捷键 ...
- JavaScript -- 时光流逝(九):Window 对象、Navigator 对象
JavaScript -- 知识点回顾篇(九):Window 对象.Navigator 对象 1. Window 对象 1.1 Window 对象的属性 (1) closed: 返回窗口是否已被关闭. ...
- JavaScript -- 时光流逝(五):js中的 Date 对象的方法
JavaScript -- 知识点回顾篇(五):js中的 Date 对象的方法 Date 对象: 用于处理日期和时间. 1. Date对象的方法 <script type="text/ ...
- JS浏览器对象:window对象、History、Location对象、Screen对象
一.JS浏览器对象-window 1.window对象 window对象是BOM的核心,window对象指当前的浏览器窗口 所有JavaScript全局对象.函数以及变量均自动成为window对象的成 ...
- JavaScript -- 时光流逝(六):js中的正则表达式 -- RegExp 对象
JavaScript -- 知识点回顾篇(六):js中的正则表达式 -- RegExp 对象 1. js正则表达式匹配字符之含义 查找以八进制数 规定的字符. 查找以十六进制数 规定 ...
- JavaScript -- 时光流逝(四):js中的 Math 对象的属性和方法
JavaScript -- 知识点回顾篇(四):js中的 Math 对象的属性和方法 1. Math 对象的属性 (1) E :返回算术常量 e,即自然对数的底数(约等于2.718). (2) LN2 ...
- JavaScript -- 时光流逝(三):js中的 String 对象的方法
JavaScript -- 知识点回顾篇(三):js中的 String 对象的方法 (1) anchor(): 创建 HTML 锚. <script type="text/javasc ...
随机推荐
- Shuffle过程
Shuffle过程 在MapReduce框架中,shuffle是连接Map和Reduce之间的桥梁,Map的输出要用到Reduce中必须经过shuffle这个环节,shuffle的性能高低直接影响了整 ...
- Response.Redirect()和Response.RedirectPermanent()区别
备注:这里我用到了Response.RedirectPermanent()用于做301跳转, 如:我希望访问网站的url访问地址为:http://m.shop/abc.html ,用户输入的访问地址: ...
- 如何定义一个有效的OWIN Startup Class
命名约定 Katana在程序集内的程序集名称空间下查找一个叫做Startup的类, 通过属性指定 [assembly: OwinStartup(typeof(OwinConsoleApp.Startu ...
- C# Winform开发以及控件开发的需要注意的,被人问怕了,都是基础常识
我是搞控件开发的,经常被人问,所以把一些问题记录了下来!如果有人再问,直接把地址丢给他看. 一. 经常会有人抱怨Winform界面闪烁,下面有几个方法可以尽可能的避免出现闪烁 1.控件的使用尽量以纯色 ...
- SpringMVC 的运行原理
0. 灵魂的拷问 问:SpringMVC 是什么?它有什么作用? 答:SpringMVC 的全称是 Spring Web Model-View-Controller,它是 Spring Fram ...
- web站点和windows服务项目发布时如何排除指定文件
在发布asp.net站点和windows服务项目时,有的时候这样的需求:msbuild编译之后发布到服务器指定目录时要排除指定文件,比如通过jenkins构建时,不希望覆盖原来的Web.config和 ...
- HTML标签笔记
换行符:<br/> 首部: <!DOCTYPE>: 说明html文档使用的标准, 在HTML5中仅为 <!DOCTYPE html>1.头标签 <head&g ...
- could not read Username for 'https://github.com': No error
用idea往github上push代码的时候,突然的不能用了. 报could not read Username for 'https://github.com': No error错误. 原因不明. ...
- Java中枚举的使用
Java中枚举其实就是静态常量,今天发现枚举里面其实还能加方法,学习了下, 代码如下: package org.pine.test; import java.util.HashMap; import ...
- 二进制安装 kubernetes 1.12(五) - 运行测试实例
检查集群状态 # 在 master 上 kubectl get node kubectl get cs 注册登录阿里云容器仓库 因国内无法获得 google 的 pause-amd64 镜像,我这里使 ...