2013-09-16 75 views
1

我想检索html内容宽度。假设当我们将窗口大小调整为较小的大小时,滚动条就会出现,所以我想要获取整个html内容的宽度以及由于垂直滚动条而不可见的内容。如何获取html内容宽度不是窗口宽度

回答

0

你可以试试这个: -

var width = document.getElementById('foo').offsetWidth; 

试试这个代码:

window.moveTo(0,0); 
window.resizeTo(screen.width,screen.height); 
var navButtonsEtcHeight = screen.height - window.innerHeight; 
var navButtonsEtcWidth = screen.width - window.innerWidth; 
+0

我试过,但它只是给我的HTML内容是可见的不是可见的内容的宽度的宽度由于垂直滚动条 – abc

+0

是的,我试过了,但它给我窗口的宽度,而不是整个html内容的宽度 – abc

+0

尝试使用window.outerWidth和window.innerWidth –

0

您可以使用window.outerWidthwindow.innerWidth

+0

较低版本的IE不支持window.outerwidth – abc

0

这里的浏览器窗口的Fiddle

<div></div> 


$(function() { 

    var dWth = $(document).innerWidth(), 
     dHgt = $(document).innerHeight(); 

    $('div').append('<h2>'+dWth+'px X '+dHgt+'px</h2>'); 

    $(window).resize(function() { 

    var dWth = $(document).innerWidth(), 
     dHgt = $(document).innerHeight(); 

    $('div').html('<h2>'+dWth+'px X '+dHgt+'px</h2>'); 
    }); 

}); 

$(window).width();         //返回宽度HTML文档