JavaScript Screen对象属性方法 小结

       虽然写这个博客主要目的是为了给我自己做一个思路记忆录,但是如果你恰好点了进来,那么先对你说一声欢迎。我并不是什么大触,只是一个菜菜的学生,如果您发现了什么错误或者您对于某些地方有更好的意见,非常欢迎您的斧正!

学习来源:http://www.w3school.com.cn/jsref/dom_obj_screen.asp

Screen 对象

Screen 对象包含有关客户端显示屏幕的信息。

 

Screen 对象属性

属性描述
availHeight返回显示屏幕的高度 (除 Windows 任务栏之外)。
availWidth返回显示屏幕的宽度 (除 Windows 任务栏之外)。
bufferDepth设置或返回调色板的比特深度。
colorDepth返回目标设备或缓冲器上的调色板的比特深度。
deviceXDPI返回显示屏幕的每英寸水平点数。
deviceYDPI返回显示屏幕的每英寸垂直点数。
fontSmoothingEnabled返回用户是否在显示控制面板中启用了字体平滑。
height返回显示屏幕的高度。
logicalXDPI返回显示屏幕每英寸的水平方向的常规点数。
logicalYDPI返回显示屏幕每英寸的垂直方向的常规点数。
pixelDepth返回显示屏幕的颜色分辨率(比特每像素)。
updateInterval设置或返回屏幕的刷新率。
width返回显示器屏幕的宽度。

 

我的测试结果:每一个按钮点击后就可以出现相应的函数效果

就像这样:

以下是源代码(有哪里需要我加注释的,欢迎在评论区与我交流):

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Screen 对象</title>
  <style media="screen" type="text/css">
    body {
      margin: 0;
      padding: 0;
    }

    input {
      margin-left: 50px;
      margin-top: 10px;
      display: block;
      font-size: 20px;
    }

    p {
      margin-left: 50px;
      font-size: 20px;
    }
  </style>
  <script type="text/javascript">
    function AvailHeight() {
      document.getElementById('availheight').innerHTML = screen.availHeight;
    }

    function BufferDepth() {
      document.getElementById('bufferdepth').innerHTML = screen.bufferDepth;
    }

    function Height() {
      document.getElementById('height').innerHTML = screen.height;
    }
  </script>
</head>

<body>
  <input type="button" value="availHeight返回显示屏幕的高度 (除 Windows 任务栏之外)。" onclick="AvailHeight()">
  <p id="availheight"></p>
  <input type="button" value="bufferDepth设置或返回调色板的比特深度。" onclick="BufferDepth()">
  <p id="bufferdepth"></p>
  <input type="button" value="height返回显示屏幕的高度。" onclick="Height()">
  <p id="height"></p>
</body>

</html>

History 对象

History 对象包含用户(在浏览器窗口中)访问过的 URL。

History 对象是 window 对象的一部分,可通过 window.history 属性对其进行访问。

 

History 对象属性

属性描述
length返回浏览器历史列表中的 URL 数量。

History 对象方法

方法描述
back()加载 history 列表中的前一个 URL。
forward()加载 history 列表中的下一个 URL。
go()加载 history 列表中的某个具体页面。

 

以下是源代码

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>History对象</title>
  <style media="screen" type="text/css">
    body {
      margin: 0;
      padding: 0;
    }

    input {
      margin-left: 50px;
      margin-top: 10px;
      display: block;
      font-size: 20px;
    }

    p {
      margin-left: 50px;
      font-size: 20px;
    }
  </style>
  <script type="text/javascript">
    function Length() {
      document.getElementById('length').innerHTML = history.length;
    }

    function Back() {
      window.history.back();
    }

    function Forward() {
      window.history.forward();
    }

    function Go() {
      window.history.go(-1);
    }
  </script>
</head>

<body>
  <input type="button" value="length返回浏览器历史列表中的 URL 数量。" onclick="Length()">
  <p id="length"></p>
  <input type="button" value="back()加载 history 列表中的前一个 URL" onclick="Back()">
  <input type="button" value="forward()加载 history 列表中的下一个 URL" onclick="Forward()">
  <input type="button" value="go()加载 history 列表中的某个具体页面。" onclick="Go()">

</body>

</html>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值