浏览器大小(宽度和高度)

我正在尝试检测浏览器的当前大小(宽度和高度)。我知道在jquery中使用$(document).width and $(document).height非常简单,但我不想将jquery lib的大小添加到项目中,所以我宁愿使用内置的javascript。用JavaScript做同样的事情的快捷有效的方法是什么?


最佳答案:

// first get the size from the window
// if that didn't work, get it from the body
var size = {
  width: window.innerWidth || document.body.clientWidth,
  height: window.innerHeight || document.body.clientHeight
}