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

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

问题描述

让我开始说我是附加开发的新手。使用附加SDK,我试图创建一个简单的Firefox附加组件,当按下按钮时,按下Ctrl-S热键,或按照文件→保存页面来获得保存页面弹出窗口。我已经在这里看过类似的问题,但是他们似乎正在使用内置的保存功能,而不是使用保存页面窗口。



最终目标是在保存调用之前运行其他函数。用户只能看到正常的保存页面窗口。

我不知道如何发送热键信号,或从附件中访问文件下拉菜单。

解决方案

一种方法是像用户一样调用另存为对话框点击Save Page As ...菜单项( id =menu_savePage)。您可以通过执行该菜单项的 doCommand()方法来执行此操作。以下假定传入的事件是用户点击的按钮的命令事件。

  function launchSaveAsFromButton(event){

var window = event.view;

//创建一些公共变量,如果它们不存在的话。
//这可以在任何Firefox环境下工作。
//根据函数运行的上下文,
//这可以被简化。
if(window === null || typeof window!==object){
//如果您还没有窗口引用,您需要获取一个:
/ /添加/以取消注释适合您的加载项类型的代码。
// *附加SDK:
var window = require('sdk / window / utils')。getMostRecentBrowserWindow();
// * /
/ *覆盖和引导(几乎来自任何上下文/作用域):
var window = Components.classes [@ mozilla.org/appshell/window-mediator;1 ]
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow(navigator:browser);
//

if(typeof document ===undefined){
//如果没有定义文档,可以获取
var document = window.content.document;

if(typeof gBrowser ===undefined){
//如果没有定义gBrowser,可以获得
var gBrowser = window.gBrowser;
}

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

$ / code>

查找Save Page As ...对话框的ID是通过将 DOM检查器与附加组件元素检查器


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.

解决方案

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();
}

Finding out the ID for the "Save Page As..." dialog is made easier by using the DOM Inspector in combination with the add-on Element Inspector.

这篇关于使用文件保存带有Firefox插件的网页 - >保存为弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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