使用文件-& gt保存带有Firefox插件的网页.另存为弹出窗口 [英] Save web pages with Firefox addon using file -> save as pop-up window

查看:74
本文介绍了使用文件-& gt保存带有Firefox插件的网页.另存为弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我说我是附加开发的新手.我正在使用附加软件开发工具包,尝试创建一个简单的Firefox附加软件,当按下按钮时,其行为类似于按Ctrl-S热键,或遵循文件->保存页面以使保存页面弹出上窗口.我在这里已经看过类似的问题,但是它们似乎是围绕内置的保存功能,而不是利用另存为"窗口.

Let me start off by saying I am new to add-on development. Using the Add-on SDK, I am trying to create a simple Firefox add-on that, when a button is pressed, acts like pressing the Ctrl-S hotkey, or following the file -> save page as to get the save page pop up window. I have looked at similar questions on here, but they seem to be going around the built in save functions, and not utilizing the "save page as" window.

最终目标是在进行保存调用之前运行其他功能.用户将只能正常看到保存页面"窗口.

The end goal is to run other functions before the save call is made. The user will only see the save page window as normal.

我不知道发送热键信号或从附加组件访问文件下拉菜单的方法.

I am unaware of ways to send hotkey signals, or accessing the file drop down menu from within an add-on.

推荐答案

执行此操作的一种方法是完全调用另存为对话框,就像用户单击另存为页面"一样...菜单项( id =" menu_savePage").您可以通过执行该菜单项的 doCommand()方法来执行此操作.以下假设传入的 event 是用户单击按钮的 command 事件.

One way to do this is to invoke the Save As dialog exactly as if the user had clicked on the "Save Page As..." menu item (id="menu_savePage"). You can do this by executing the doCommand() method of that menu item. The following assumes that the event passed in is the command event for the button that the user clicked.

function launchSaveAsFromButton(event) {

    var window = event.view;

    //Create some common variables if they do not exist.
    //  This should work from any Firefox context.
    //  Depending on the context in which the function is being run,
    //  this could be simplified.
    if (window === null || typeof window !== "object") {
        //If you do not already have a window reference, you need to obtain one:
        //  Add a "/" to un-comment the code appropriate for your add-on type.
        //* Add-on SDK:
        var window = require('sdk/window/utils').getMostRecentBrowserWindow();
        //*/
        /* Overlay and bootstrap (from almost any context/scope):
        var window=Components.classes["@mozilla.org/appshell/window-mediator;1"]
                             .getService(Components.interfaces.nsIWindowMediator)
                             .getMostRecentWindow("navigator:browser");
        //*/
    }
    if (typeof document === "undefined") {
        //If there is no document defined, get it
        var document = window.content.document;
    }
    if (typeof gBrowser === "undefined") {
        //If there is no gBrowser defined, get it
        var gBrowser = window.gBrowser;
    }

    let menuSavePage = gBrowser.ownerDocument.getElementById("menu_savePage");
    menuSavePage.doCommand();
}

使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆