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 对象的更多相关文章

  1. JavaScript -- 时光流逝(十三):DOM -- Console 对象

    JavaScript -- 知识点回顾篇(十三):DOM -- Console 对象 (1) assert() : 如果断言为 false,则在信息到控制台输出错误信息.(2) clear() : 清 ...

  2. JavaScript -- 时光流逝(十一):DOM -- Document 对象

    JavaScript -- 知识点回顾篇(十一):DOM -- Document 对象 (1) document.activeElement: 返回文档中当前获得焦点的元素. <!doctype ...

  3. JavaScript -- 时光流逝(十二):DOM -- Element 对象

    JavaScript -- 知识点回顾篇(十二):DOM -- Element 对象 (1) element.accessKey: 设置或返回accesskey一个元素,使用 Alt + 指定快捷键 ...

  4. JavaScript -- 时光流逝(九):Window 对象、Navigator 对象

    JavaScript -- 知识点回顾篇(九):Window 对象.Navigator 对象 1. Window 对象 1.1 Window 对象的属性 (1) closed: 返回窗口是否已被关闭. ...

  5. JavaScript -- 时光流逝(五):js中的 Date 对象的方法

    JavaScript -- 知识点回顾篇(五):js中的 Date 对象的方法 Date 对象: 用于处理日期和时间. 1. Date对象的方法 <script type="text/ ...

  6. JS浏览器对象:window对象、History、Location对象、Screen对象

    一.JS浏览器对象-window 1.window对象 window对象是BOM的核心,window对象指当前的浏览器窗口 所有JavaScript全局对象.函数以及变量均自动成为window对象的成 ...

  7. JavaScript -- 时光流逝(六):js中的正则表达式 -- RegExp 对象

    JavaScript -- 知识点回顾篇(六):js中的正则表达式 -- RegExp 对象 1. js正则表达式匹配字符之含义      查找以八进制数 规定的字符.     查找以十六进制数 规定 ...

  8. JavaScript -- 时光流逝(四):js中的 Math 对象的属性和方法

    JavaScript -- 知识点回顾篇(四):js中的 Math 对象的属性和方法 1. Math 对象的属性 (1) E :返回算术常量 e,即自然对数的底数(约等于2.718). (2) LN2 ...

  9. JavaScript -- 时光流逝(三):js中的 String 对象的方法

    JavaScript -- 知识点回顾篇(三):js中的 String 对象的方法 (1) anchor(): 创建 HTML 锚. <script type="text/javasc ...

随机推荐

  1. [EOJ629] 两开花

    Description 给定一棵以 \(1\) 为根 \(n\) 个节点的树. 定义 \(f(k)\) :从树上等概率随机选出 \(k\) 个节点,这 \(k\) 个点的虚树大小的期望. 一个点 \( ...

  2. 翻译:SET子句(已提交到MariaDB官方手册)

    本文为mariadb官方手册:SET的译文. 原文:https://mariadb.com/kb/en/set/我提交到MariaDB官方手册的译文:https://mariadb.com/kb/zh ...

  3. [转]如何查看oracle用户具有的权限和角色

    本文转自:https://www.cnblogs.com/qlqwjy/p/8404959.html 1.查看所有用户: select * from dba_users; select * from ...

  4. .net 模拟登陆 post https 请求跳转页面

    AllowAutoRedirect property is true, the Referer property is set automatically when the request is re ...

  5. 验证码图片二值化问题 BitmapData 怎么解决

    对不起,这算是一篇求助啦,先上图,防止不清楚,放大了一点,下面是图片,上面是没有二值化的,下面是二值化之后的,我其实不懂什么是二值化啦,就是一定范围变黑,变白 问题: 为什么我的结果上面还是有很多彩色 ...

  6. WPF 自定义Command

    无参Command: internal class DelegateCommand : ICommand { private readonly Action _execute; private rea ...

  7. oracle expdp自动备份脚本

    windows: @echo off echo ================================================ echo Windows环境下Oracle数据库的自动 ...

  8. JSJ—案例谈面向对象

    有人告诉我那里遍地都是对象——我们把所有的程序代码放在main()里面,事实上,那根本就不是面向对象的做法,在Java的面向对象中,我们也会看到类和对象的不同,以及对象是如何让你的生活更美好(至少程序 ...

  9. PHP实现二分法查找

    二分查找法需要数组是一个有序的数组. <?php function binarySearch($num, $arr) { $start = 0; $end = count($arr); $mid ...

  10. ASP.NET MVC 使用Jquery异步操作JS代码

    $(function () { var ajaxFormSubmit = function () { var $form = $(this); var options = { url: $form.a ...