Controlling sdk sidebar width for Firefox

I am creating a Firefox add -on with the Add-on SDK . My add-on uses a sidebar created using the ui / sidebar API . Is there a way to control the initial width of this sidebar?

The user can drag to resize it, but I would like it to start with a larger width than it seems by default. Is it possible?

Thank.

+4
source share
2 answers

Using window / utils , you can get the topmost browser window as nsIDOMWindow , then you can get the sidebar element of this window as an HTML element that allows you to change its CSS properties:

var utils = require('sdk/window/utils');
var win = utils.getMostRecentBrowserWindow();
if (utils.isBrowser (win))
{
    var sidebar = win.document.getElementById ("sidebar");
    sidebar.style.minWidth = "340px";
    sidebar.style.width = "340px";
    sidebar.style.maxWidth = "500px";
}

Please note that this will affect all sidebars of the top-most open firefox window (including bookmarks and sidebars);

+3
source

Yes use the width in the style attribute. Or use min-width. howstyle: 'min-width: 14em; width: 18em; max-width: 36em;'

Here is the addon that creates the sidebar. You can install it, its ready-made demonstration. _ ff-addon-BootstrapSidebar

0
source

Source: https://habr.com/ru/post/1530533/


All Articles