JavaScript中innerWidth和innerHeight属性详解


当前第2页 返回上一页

示例:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>浏览器内部的宽度和高度</title>

    <style>

        body{

            text-align:center;

        }

        .gfg {

            font-size:40px;

            font-weight:bold;

            color:green;

        }

    </style>

</head>

<body>

<div class = "gfg">PHP中文网</div>

<h2>浏览器窗口</h2>

<p id="demo"></p>

<script>

    var Width, Height, result;

 

    // 浏览器窗口的高度和宽度

    Width = window.innerWidth || document.documentElement.clientWidth

        || document.body.clientWidth;

 

    Height = window.innerHeight || document.documentElement.clientHeight

        || document.body.clientHeight;

    // 显示宽度和高度。

    result = document.getElementById("demo");

    result.innerHTML = "浏览器内部宽度: " + Width +

        "<br>浏览器内部高度: " + Height;

 

</script>

</body>

</html>

输出:

09954caece181f0b7f7322afc6258ab.png

相关推荐:《javascript教程》

本篇文章就是关于JavaScript中Window innerWidth和innerHeight属性的相关介绍,希望对需要的朋友有所帮助!

以上就是JavaScript中innerWidth和innerHeight属性详解的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

js proxy 的优势以及使用场景

详解js中的window.location对象(备忘单)

javascript操作dom对象之select(详细解答)

javascript中对象一般由什么组成

html5 canvas实现中奖转盘的实例代码

javascript中this什么意思

java和javascript啥关系

js数组学习之清空全部元素的4种方法(代码详解)

javascript有没有二维数组

javascript如何设置select值

更多相关阅读请进入《javascript》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...