2014-03-28 54 views

回答

2
const { getMostRecentBrowserWindow } = require('sdk/window/utils'); 

var chromewin = getMostRecentBrowserWindow(); 
chromewin.PrintUtils.printPreview(chromewin.PrintPreviewListener); 
+0

有人說../main無權負荷:SDK /窗/ utils的 – mangovn

+0

內容腳本禁止使用SDk API,'main.js'沒問題。親自嘗試一下。 – paa

+0

我在main.js中寫這個。 Just:const {getMostRecentBrowserWindow} = require('sdk/window/utils'); 瀏覽器控制檯警告/主沒有權限加載:sdk/window/utils。 我在我的插件中使用somuch庫 const widgets = require(「sdk/widget」); const data = require(「sdk/self」)。data; var preferences = require(「sdk/preferences/service」);preferences.set(「print.save_print_settings」,true); var tabs = require('sdk/tabs'); var {Cc,Ci,Cu} = require(「chrome」); var {Hotkey} = require(「sdk/hotkeys」); const {getMostRecentBrowserWindow} = require('sdk/window/utils');; //這一行返回錯誤 – mangovn

1
const BROWSER = 'navigator:browser' ; 
var {Cc, Ci, Cu} = require("chrome"); 
const WM = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator); 
function getMostRecentBrowserWindow() { 
return getMostRecentWindow(BROWSER); 
} 
exports.getMostRecentBrowserWindow = getMostRecentBrowserWindow; 
function getMostRecentWindow(type) { 
return WM.getMostRecentWindow(type); 
} 
exports.getMostRecentWindow = getMostRecentWindow; 
var chromewin = getMostRecentBrowserWindow(); 
chromewin.PrintUtils.printPreview(chromewin.PrintPreviewListener); 

這個工作

相關問題