Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我如何确定IE相对较新版本的高度和宽度(过去,IE8不喜欢从JavaScript设置这种样式的哪些方面?)_Javascript_Html_Css_Internet Explorer 8_Cross Browser - Fatal编程技术网

我如何确定IE相对较新版本的高度和宽度(过去,IE8不喜欢从JavaScript设置这种样式的哪些方面?)

我如何确定IE相对较新版本的高度和宽度(过去,IE8不喜欢从JavaScript设置这种样式的哪些方面?),javascript,html,css,internet-explorer-8,cross-browser,Javascript,Html,Css,Internet Explorer 8,Cross Browser,IE8报告这两行中的第二行出现错误。(返回高度和宽度的函数返回窗口高度和宽度的整数。) 你在抱怨什么 --编辑-- 我在一个容纳IE4但可能不是IE最新版本的地方编写代码;我只是希望有人能够彻底解决IE4问题,这对IE的普通版本来说是有意义的。代码返回0表示窗口高度,下一行则抱怨它的高度为-200px。 给出的代码是: var height = (library.window_dimensions().height - 200) + 'px'; document.getElementById('

IE8报告这两行中的第二行出现错误。(返回高度和宽度的函数返回窗口高度和宽度的整数。)

你在抱怨什么

--编辑--

我在一个容纳IE4但可能不是IE最新版本的地方编写代码;我只是希望有人能够彻底解决IE4问题,这对IE的普通版本来说是有意义的。代码返回0表示窗口高度,下一行则抱怨它的高度为-200px。

给出的代码是:

var height = (library.window_dimensions().height - 200) + 'px';
document.getElementById('activity-feed').style.height = height;

因此,我的下一个问题是:在不必回到IE6之前的情况下,如何确定宽度和高度,以便例如IE8获得正确的高度?

很可能,您没有到达元素。getElementByID()是一个时髦的函数。您正在尝试设置空/未定义的高度。

是否执行
getElementById
return
null
?以这种方式设置高度在IE8中应该可以正常工作。您必须在其他地方找到错误,例如,如果getElement未返回任何元素。调试时,什么是
var height=(library.window_dimensions().height-200)+“px”值?
function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}