HTA ウィンドウのサイズを設定することはできますが、そのサイズを取得する方法が見つかりません。
私が考えることができるのは と を読むdocument.body.offsetWidth
こと.offsetHeight
だけですが、それらは実際のウィンドウサイズではなくビューポートサイズを示します。
それを知ることは可能ですか?
HTA ウィンドウのサイズを設定することはできますが、そのサイズを取得する方法が見つかりません。
私が考えることができるのは と を読むdocument.body.offsetWidth
こと.offsetHeight
だけですが、それらは実際のウィンドウサイズではなくビューポートサイズを示します。
それを知ることは可能ですか?
その情報を取得するためのプロパティやメソッドはないようです。現在ベータ版がリリースされている 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) ;
}
この関数が行うことは、オブジェクトの 2 つの新しいメソッドを作成すること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()
を取得する 2 つの新しいメソッドを作成します。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}
})};