2

HTA ウィンドウのサイズを設定することはできますが、そのサイズを取得する方法が見つかりません。

私が考えることができるのは と を読むdocument.body.offsetWidthこと.offsetHeightだけですが、それらは実際のウィンドウサイズではなくビューポートサイズを示します。

それを知ることは可能ですか?

4

2 に答える 2

2

その情報を取得するためのプロパティやメソッドはないようです。現在ベータ版がリリースされている IE9 には新しいプロパティoutterWidthoutterHeightがありますが、現時点ではオプションではありません。

だから私はこれに対する回避策を考案しました:

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()

問題が解決しました。関数がどのように機能するかは皆さんに理解してもらいましょう ;)

于 2011-04-01T19:12:14.863 に答える
1

縮小版:

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}
})};
于 2014-10-22T13:04:43.943 に答える