如何获得整个网页的高度? javascript

时间:2018-08-05 06:09:13

标签: javascript height

如何使用javascript获取网页的完整高度? 例如,网页是4138像素。如何使用javascript ??? clientheight仅给出屏幕的高度,我不希望这样。

2 个答案:

答案 0 :(得分:1)

您可以使用outerHeight来找到网页的高度。您应该在网站上使用jQuery。 像这样使用:

$('body').outerHeight()

对于纯Javascript,请使用以下代码:

var height = document.querySelector('body').clientHeight
console.log(height)

答案 1 :(得分:0)

To get the height of the Web Page using javascript, you can make use of the method "height". Here is an example where you can get the height of the webpage using javascript in pixel

<!DOCTYPE html>
<html>
<body>

<p>Click the button to display the total height of your screen, in pixels.</p>

<button onclick="myFunction()">Try it</button>

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

<script>
function myFunction() {
    var x = "Height of the Screen in Pixel is : " + screen.height + "px";
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

因此,“ screen.height”方法将为您提供像素的高度。