您可以设置 HTA 窗口的大小,但我找不到获取其大小的方法。
我能想到的只是阅读document.body.offsetWidth
and .offsetHeight
,但那些给你的是视口大小而不是实际的窗口大小。
有可能知道吗?
您可以设置 HTA 窗口的大小,但我找不到获取其大小的方法。
我能想到的只是阅读document.body.offsetWidth
and .offsetHeight
,但那些给你的是视口大小而不是实际的窗口大小。
有可能知道吗?
似乎没有获取该信息的属性或方法。现已发布 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
标记之后执行。
现在我们已经完成了,同样的问题也适用于窗口位置。您无法获得实际的窗口位置。您可以获得的是相对于屏幕的视口位置。因此,同样的解决方法也适用于此:
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 screenLeft-'+viewportOffsetX) ;
window.getScreenY = new Function('return screenTop-'+viewportOffsetY) ;
}
同样,该函数创建了两个将检索实际窗口位置的新方法:window.getScreenX()
和window.getScreenY()
问题解决了。我会让你们弄清楚这个功能是如何工作的;)
缩小版:
window.pos=new function(w,h,x,y){with(document.body)return(
resizeTo(w=offsetWidth,h=offsetHeight),resizeTo(w+(w=w-offsetWidth),h+(h=h-offsetHeight)),
moveTo (x=screenLeft ,y=screenTop ),moveTo (x-(x=screenLeft-x ),y-(y=screenTop-y )),{
w:function(){return offsetWidth +w},
h:function(){return offsetHeight+h},
x:function(){return screenLeft -x},
y:function(){return screenTop -y}
})};