2012-11-26 48 views
1

我想使用chrome.create.window來獲得一個彈出窗口,並出現一些問題。Chrome擴展程序create.window:如何使用高度參數?

這裏是我的background.js代碼:

chrome.extension.onRequest.addListener(function(request) { 
if (request.type === 'open_window') { 
     chrome.tabs.create({ 
      url: chrome.extension.getURL('win.html'), 
      active: false 
     }, function(tab) { 
      chrome.windows.create({ 
       tabId: tab.id, 
       type: 'popup', 
       height: '200', 

       focused: true 
      }); 
     }); 
} 
}); 

之前我已經添加height: '200',我得到了我想要的:一個窗口跳出瀏覽器。當我添加這一行時,該窗口作爲打開窗口的另一個選項卡打開。爲什麼 ?

回答

2

使用數字代替字符串:200"200"。你會知道,如果你opened the console for the background page

Uncaught Error: Invalid value for argument 1. Property 'height': Expected 'integer' but got 'string'.

我建議使用url選項與chrome.windows.create,因爲它會更有效:

chrome.windows.create({ 
    url: chrome.extension.getURL('win.html'), 
    type: 'popup', 
    height: 200, 
    focused: true 
}); 
+0

謝謝。我打開了控制檯,沒有看到任何錯誤。我一定錯過了什麼。我會檢查它。提示+1。 – Subway