4

js ファイルの window.open に resizable = 1 を指定して新しいウィンドウで起動する scorm モジュールがあります。

function OpenScormModuleWindow(scormModuleId, scormModuleUrl, title, width, height) 
{
  _scormModuleId = scormModuleId;
  InitializeUserScormModule();
  scormModuleWindow = window.open(scormModuleUrl, "title", "width=" + width + ", height=" + height + ", resizable = 1");
  scormModuleWindow.focus();
}

私の見解では:

  var myWidth = 0, myHeight = 0;
  if (typeof (window.innerWidth) == 'number')
  {
      myWidth = window.innerWidth;
      myHeight = window.innerHeight;
  }
  else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
  {
      myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight;
  }
  else if (document.body && (document.body.clientWidth || document.body.clientHeight))
  {
      myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
  }

高さと幅を取得しましたが、正しくありません

ウィンドウが正しいサイズの場合、ユーザーはサイズを変更できるようになりました。高さと幅を取得するにはどうすればよいですか?

これらの値を取得して保存できるようにする必要があります。次にウィンドウが開いたときに正しいサイズになります。

ありがとう

4

3 に答える 3

11

サイズ変更をリッスンするイベントリスナーを使用すると、値をリセットできます。

window.addEventListener('resize', setWindowSize);

function setWindowSize() {
  if (typeof (window.innerWidth) == 'number') {
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else {
    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    } else {
      if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
    }
  }
}

クロスブラウザソリューションが必要な場合は、jQuery$.on('resize', func))を使用するか、JavaScriptウィンドウのサイズ変更イベントを参照してください

于 2012-09-26T07:07:26.957 に答える
0

私が見る限り、これが最善の方法です。

function resizeCanvas() {
    canvas.width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    canvas.height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

    WIDTH = canvas.width;
    HEIGHT = canvas.height;
}
于 2016-12-31T15:51:42.503 に答える