似乎没有属性或方法来获取该信息。现在发布的beta版IE9具有新属性outterWidth和outterHeight,但现在不是一个选项。
所以我为此设计了一个解决方法:
function addWinSizeGetterFuncs(){
var currViewportWidth = document.body.offsetWidth ;
var currViewportHeight = document.body.offsetHeight ;
resizeTo(currViewportWidth,currViewportHeight) ;
var chromeWidth = currViewportWidth-document.body.offsetWidth ;
var chromeHeight = currViewportHeight-document.body.offsetHeight ;
resizeTo(currViewportWidth+chromeWidth,currViewportHeight+chromeHeight) ;
window.getWidth = new Function('return document.body.offsetWidth+'+chromeWidth) ;
window.getHeight = new Function('return document.body.offsetHeight+'+chromeHeight) ;
}该函数的作用是为window对象创建两个新方法:window.getWidth()和window.getHeight()。他们将获得窗口的实际大小。
该函数需要存在body对象,因此必须在BODY标记之后执行。
现在我们就在这里,同样的问题适用于窗口位置。你无法获得实际的窗口位置。你可以得到的是相对于屏幕的视口位置。
所以同样的workaroud也适用于此:
function addWinPosGetterFuncs(){
var currViewportLeft = screenLeft ;
var currViewportTop = screenTop ;
moveTo(currViewportLeft,currViewportTop) ;
var viewportOffsetX = screenLeft-currViewportLeft ;
var viewportOffsetY = screenTop-currViewportTop ;
moveTo(currViewportLeft-viewportOffsetX,currViewportTop-viewportOffsetY) ;
window.getScreenX = new Function('return '+viewportOffsetX) ;
window.getScreenY = new Function('return '+viewportOffsetY) ;
}同样,该函数创建两个新方法来检索实际窗口位置:window.getScreenX()和window.getScreenY()
问题解决了。我会让你们弄清楚这个功能是如何工作的;)