0

私の拡張機能は、次の条件でポップアップ ウィンドウ (デフォルトの拡張機能のポップアップではなく、通常のポップアップ ウィンドウ) を開く必要があります。

  1. その瞬間に開くことができるウィンドウは 1 つだけでした。
  2. ウィンドウのサイズと位置を localStorage に保存し、次に開いたときにそれらを復元したいと考えています。

その方法は?

私は試した:

chrome.browserAction.onClicked.addListener(function() {

  // 1. In this case, variable win is a window object. But it's empty. There
  // is no properties/methods to operate with.
  var win = window.open('http://example.com','windowname');

  chrome.windows.create({
    'url': 'http://example.com',
    'type': 'popup'
  }, function(win) {
    // 2. In this case, variable win has some properties, but they are static
    // and won't change on window resize/close.
  });
});

何か案は?

4

1 に答える 1

0

でこれを行うことができると思いますwindow.open()

1-現時点で開くことができるウィンドウは 1 つだけです。

name同じ, window.open(),を与えると

  • 同じ名前のウィンドウが存在しない場合は、新しいウィンドウを作成します
  • それ以外の場合、同じ名前の開いているウィンドウがある場合は、それを更新するだけです。

2- ウィンドウのサイズと位置を localStorage に保存し、次に開いたときにそれらを復元したい。

window.onresizeはい、イベントを添付することでこれを行うことができます。

これが基本的な例です。

chrome.browserAction.onClicked.addListener(function() {
  var wOpt = getWindowDefaultOptions(); // options from localStorage
  var win = window.open("http://www.example.com", "myscriptpopup", "width="+wOpt.width+", height="+wOpt.height+", top="+wOpt.top+", left="+wOpt.left);
  win.onresize = function() {
      var newOptions = {};
      newOptions.width = this.innerWidth;
      newOptions.height = this.innerHeight;
      newOptions.top = this.screenY;
      newOptions.left = this.screenX;
      setWindowDefaultOptions(newOptions); //save Options to localStorage
  }
});

//Default Options For Window
var winOptions = {
      "width" : "200",
      "height" : "100",
      "top" : "50",
      "left" : "50"
};
于 2012-11-24T18:13:36.380 に答える