【问题标题】:How to call Firefox printpreview using addon SDK如何使用插件 SDK 调用 Firefox printpreview
【发布时间】:2014-03-28 03:18:44
【问题描述】:

如何使用插件 SDK 调用 Firefox printpreview。 最新 SDK (1.16) 不包含printultis.js

非常感谢

【问题讨论】:

    标签: firefox firefox-addon firefox-addon-sdk


    【解决方案1】:
    const { getMostRecentBrowserWindow } = require('sdk/window/utils');
    
    var chromewin = getMostRecentBrowserWindow();
    chromewin.PrintUtils.printPreview(chromewin.PrintPreviewListener);
    

    【讨论】:

    • 据说../main无权加载:sdk/window/utils
    • 内容脚本被禁止使用 SDK API,main.js 可以。自己试试吧。
    • 我在 main.js 中写了这个。只是: const { getMostRecentBrowserWindow } = require('sdk/window/utils');浏览器控制台警告 /main 无权加载:sdk/window/utils。我在我的插件中使用了一些库 const widgets = require("sdk/widget");常量数据 = 要求(“sdk/self”).data; var preferences = require("sdk/preferences/service");首选项.set("print.save_print_settings",true); var tabs = require('sdk/tabs'); var {Cc,Ci,Cu} = 要求(“铬”); var { Hotkey } = require("sdk/hotkeys"); const { getMostRecentBrowserWindow } = require('sdk/window/utils');;//这行返回bug
    • 请将您的电子邮件地址发送给我。我会寄给你我的插件包。你救了我的命。非常感谢。
    • 支持和接受答案是绰绰有余的奖励。您找到导致no authority to load 消息的原因了吗?
    【解决方案2】:
    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);
    

    成功了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-22
      • 1970-01-01
      相关资源
      最近更新 更多