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



如何使用javascript获取网页的全高?例如,网页是4138像素。如何使用javascript获得它???客户端高度只给出屏幕的高度,我不想要这个。

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

$('body').outerHeight()

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

var height = document.querySelector('body').clientHeight
console.log(height)
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"将给出像素的高度。

最新更新