This module exports a single constructor function `Panel` which constructs a new panel. A panel is a dialog. Its content is specified as HTML and you can execute scripts in it, so the appearance and behaviour of the panel is limited only by what you can do using HTML, CSS and JavaScript. The screenshot below shows a panel whose content is built from the list of currently open tabs: Simple panel example Panels are useful for presenting temporary interfaces to users in a way that is easier for users to ignore and dismiss than a modal dialog, since panels are hidden the moment users interact with parts of the application interface outside them. A panel's content is loaded as soon as it is created, before the panel is shown, and the content remains loaded when a panel is hidden, so it is possible to keep a panel around in the background, updating its content as appropriate in preparation for the next time it is shown. Your add-on can receive notifications when a panel is shown or hidden by listening to its `show` and `hide` events. ## Panel Content ## The panel's content is specified as HTML, which is loaded from the URL supplied in the `contentURL` option to the panel's constructor. You can load remote HTML into the panel: var panel = require("panel").Panel({ width: 180, height: 180, contentURL: "https://en.wikipedia.org/w/index.php?title=Jetpack&useformat=mobile" }); panel.show(); Wikipedia Jetpack panel You can also load HTML that's been packaged with your add-on, and this is most probably how you will create dialogs. To do this, save the HTML in your add-on's `data` directory and load it using the `data.url()` method exported by the [`self`](packages/addon-kit/self.html) module, like this: var panel = require("panel").Panel({ contentURL: require("self").data.url("myFile.html") }); panel.show(); ## Updating Panel Content ## You can update the panel's content simply by setting the panel's `contentURL` property. Here's an add-on that adds two widgets to the add-on bar, one which shows Google's mobile site and one which shows Bing's mobile site. The widgets share a panel object, and switch between the two sites by updating the panel's `contentURL` property: var panel = require("panel").Panel({ contentURL: "about:blank", onHide: function () { panel.contentURL = "about:blank"; } }); require("widget").Widget({ id: "bing", label: "Bing", contentURL: "http://www.bing.com/favicon.ico", panel: panel, onClick: function() { panel.contentURL = "http://m.bing.com/"; } }); require("widget").Widget({ id: "google", label: "Google", contentURL: "http://www.google.com/favicon.ico", panel: panel, onClick: function() { panel.contentURL = "http://www.google.com/xhtml"; } }); ## Scripting Panel Content ## You can't directly access your panel's content from your main add-on code. To access the panel's content, you need to load a script into the panel. In the SDK these scripts are called "content scripts" because they're explicitly used for interacting with web content. While content scripts can access the content they're attached to, they can't use the SDK's APIs. So implementing a complete solution usually means you have to send messages between the content script and the main add-on code. * You can specify one or more content scripts to load into a panel using the `contentScript` or `contentScriptFile` options to the [`Panel()` constructor](packages/addon-kit/panel.html#Panel%28options%29). * You can communicate with the script using either the [`postMessage()`](dev-guide/guides/content-scripts/using-postmessage.html) API or (preferably, usually) the [`port`](dev-guide/guides/content-scripts/using-port.html) API. For example, here's an add-on whose content script intercepts mouse clicks on links inside the panel, and sends the target URL to the main add-on code. The content script sends messages using `self.port.emit()` and the add-on script receives them using `panel.port.on()`. var myScript = "window.addEventListener('click', function(event) {" + " var t = event.target;" + " if (t.nodeName == 'A')" + " self.port.emit('click-link', t.toString());" + "}, false);" var panel = require("panel").Panel({ contentURL: "http://www.bbc.co.uk/mobile/index.html", contentScript: myScript }); panel.port.on("click-link", function(url) { console.log(url); }); panel.show(); This example uses `contentScript` to supply the script as a string. It's usually better practice to use `contentScriptFile`, which is a URL pointing to a script file saved under your add-on's `data` directory.

Unless your content script is extremely simple and consists only of a static string, don't use contentScript: if you do, you may have problems getting your add-on approved on AMO.

Instead, keep the script in a separate file and load it using contentScriptFile. This makes your code easier to maintain, secure, debug and review.

Text entry panel ### Getting User Input ### The following add-on adds a widget which displays a panel when clicked. The panel just contains a `