如何仅使用javascript将页面高度增加X像素

kno*_*orv 2 html javascript css dom

假设一个HTML页面:

<html>
  <body>
     .. html content (outside of our control) ..
     .. javascript block ..
     .. some more html content (outside of our control) ..
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

进一步假设我们能够控制的HTML页面的唯一部分是页面中间的javascript块.

使用该javascript块,如何通过"填充"页面底部将页面总高度增加150像素?

如果我可以改变HTML,一个简单的解决方案是:

<html>
  <body>
     .. html content (outside of our control) ..
     .. javascript block ..
     .. some more html content (outside of our control) ..
     <div style="height: 150px; clear: both;"></div>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

但是如何通过使用javascript块来实现这一目标呢?

理想的解决方案应该是跨浏览器兼容和100%内联(即不使用javascript库).

更新#1: javascript块可以访问页面的整个DOM.

更新#2:页面的总长度(在更改DOM之前)会有所不同.

更新#3:假设不能使用javascript库(例如优秀的jQuery).

cob*_*bal 6

更新的代码:

var space = document.createElement('div');
space.style.height = "150px";
space.style.clear = "both";
document.getElementsByTagName("body")[0].appendChild(space);
Run Code Online (Sandbox Code Playgroud)