我想在我的一个firefox扩展中创建基于xul的框架。框架应该看起来像https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/ui_frame
或
如何在xul中使用以下节点js代码:
var { Frame } = require("sdk/ui/frame");
var frame = new Frame({
url: "./city-info.html"
});
在node.js中,它的工作正常,但我不知道如何用xul创建相同的东西。有人可以帮忙吗?
提前感谢。
答案 0 :(得分:0)
您提供的内容很少,无法满足您的需求。如果你想要的只是创建一个<iframe>
,你可以在其中加载HTML内容,那么下面的内容将会这样做:
//The URL of the HTML you desire to load.
let chromeUrl = '[Some URL here]';
//Whatever element you want the iframe placed under.
let parentEl = document.getElementById('foo');
//* Overlay and bootstrap (from almost any context/scope):
Components.utils.import('resource://gre/modules/Services.jsm');//Services
let activeWindow = Services.wm.getMostRecentWindow('navigator:browser');
//*/
let mainDocument = activeWindow.document;
//Create the <iframe> use
//mainDocument for the XUL namespace.
let iframeEl;
if(options.useBrowser){
iframeEl = mainDocument.createElement('browser');
} else {
iframeEl = mainDocument.createElement('iframe');
}
iframeEl.id = id;
iframeEl.setAttribute('src',chromeUrl);
iframeEl.setAttribute("tooltip", "aHTMLTooltip");
iframeEl.setAttribute("autocompleteenabled", true);
iframeEl.setAttribute("autocompletepopup", "PopupAutoComplete");
iframeEl.setAttribute("disablehistory",true);
iframeEl.setAttribute('type', 'content');
parentEl.appendChild(iframeEl);
上面的代码取自my answer to Firefox SDK Add-on with a sidebar on both the right and left at the same time,它创建了侧边栏。如何创建这些侧边栏的一个选项是让它们包含<iframe>
。
答案 1 :(得分:0)
最后我得到了答案:
let chromeUrl = 'YOUR HTML PAGE URL';
Components.utils.import('resource://gre/modules/Services.jsm');//Services
let activeWindow = Services.wm.getMostRecentWindow('navigator:browser');
//*/
let mainDocument = activeWindow.document;
let iframeEl;
iframeEl = mainDocument.createElement('iframe');
iframeEl.id = "d";
iframeEl.setAttribute('src',chromeUrl);
iframeEl.setAttribute("tooltip", "aHTMLTooltip");
iframeEl.setAttribute("autocompleteenabled", true);
iframeEl.setAttribute("autocompletepopup", "PopupAutoComplete");
iframeEl.setAttribute("disablehistory",true);
iframeEl.setAttribute('type', 'content');
iframeEl.setAttribute('height', '32px');
window.document.documentElement.appendChild(iframeEl);