Skip to content

Instantly share code, notes, and snippets.

@ZER0
Created March 24, 2014 18:56
Show Gist options
  • Save ZER0/9746736 to your computer and use it in GitHub Desktop.
Save ZER0/9746736 to your computer and use it in GitHub Desktop.
Open a HTML Document dialog in Add-on SDK
/* Open a plain dialog */
const { getActiveTab, setTabURL } = require('sdk/tabs/utils');
const { open } = require('sdk/window/helpers');
const { data } = require('sdk/self');
const url = data.url('foo.html');
open("", {
features: {
toolbar: false,
resizable: true,
scrollbars: true,
width: 200,
height: 400
}
}).then(window => setTabURL(getActiveTab(window), url));
/* If a content script needs to be attached to the dialog */
const { getActiveTab, setTabURL, getTabId } = require('sdk/tabs/utils');
const { open } = require('sdk/window/helpers');
const { data } = require('sdk/self');
const url = data.url('foo.html');
const tabs = require('sdk/tabs');
open("", {
features: {
toolbar: false,
resizable: true,
scrollbars: true,
width: 200,
height: 400
}
}).then(window => {
let xulTab = getActiveTab(window);
let id = getTabId(xulTab);
tabs.on('ready', function ready(tab) {
if (tab.id === id) {
tabs.removeListener('ready', ready);
tab.attach({
contentScript: 'alert("hello")'
});
}
});
setTabURL(xulTab, url);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment