javascript - Save web pages with Firefox addon using file -> save as pop-up window -
let me start off saying new add-on development. using add-on sdk, trying create simple firefox add-on that, when button pressed, acts pressing ctrl-s hotkey, or following file -> save page save page pop window. have looked @ similar questions on here, seem going around built in save functions, , not utilizing "save page as" window.
the end goal run other functions before save call made. user see save page window normal.
i unaware of ways send hotkey signals, or accessing file drop down menu within add-on.
one way invoke save as dialog if user had clicked on "save page as..." menu item (id="menu_savepage"
). can executing docommand()
method of menu item. following assumes event
passed in command
event button user clicked.
function launchsaveasfrombutton(event) { var window = event.view; //create common variables if not exist. // should work firefox context. // depending on context in function being run, // simplified. if (window === null || typeof window !== "object") { //if not have window reference, need obtain one: // add "/" un-comment code appropriate add-on type. //* add-on sdk: var window = require('sdk/window/utils').getmostrecentbrowserwindow(); //*/ /* overlay , bootstrap (from 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 no document defined, var document = window.content.document; } if (typeof gbrowser === "undefined") { //if there no gbrowser defined, var gbrowser = window.gbrowser; } let menusavepage = gbrowser.ownerdocument.getelementbyid("menu_savepage"); menusavepage.docommand(); }
finding out id "save page as..." dialog made easier using dom inspector in combination add-on element inspector.
Comments
Post a Comment