我正在构建一个Firefox附加组件,我需要一个按钮,在设置页面打开一个页面的单词列表的添加 - 已存储。什么是最好的方法来做到这一点?什么是最好的方式来打开一个Firefox附加的HTML页面
我想出这个:
function ShowList() {
// We get the array from the local storage.
function createList(item){
var list = [];
// Get the stored list, if there's any.
if (item[0].list){
list = item[0].list;
}
}
function onError(e) {
alert("Error:" + e);
}
browser.storage.local.get("list").then(createList, onError);
// Once we have the list, build an HTML string with its contents
var listhtml = ['<!DOCTYPE html>',
'<html>',
' <head>',
' <meta charset="utf-8">',
' </head>',
' <body>',
' <ul>'].join("\n");
for (var w= 0; w < list.length ; w++) {
listhtml += ' <il>' + list[w][0] + '</il>\n';
}
listhtml += [' </ul>',
' </body>',
'</html>'].join("\n");
var oMyBlob = new Blob([listhtml], {type : 'text/html'}); // the blob
window.open(URL.createObjectURL(oMyBlob));
}
但HTML里面一个字符串看起来很可怕。有什么建议么?
你在做什么[Firefox扩展](https://developer.mozilla.org/en-US/Add-ons)([WebExtensions](https://developer.mozilla.org/en-US) /附加组件/ WebExtensions)[[tag:firefox-webextensions]],[Add-on SDK](https://developer.mozilla.org/en-US/Add-ons/SDK)[[tag:fiirefox- addon-sdk]],[Bootstraped](https://developer.mozilla.org/en-US/Add-ons/Bootstrapped_extensions)[[tag:firefox-addon-restartless]]或[Overlay/XUL/Legacy] (https://developer.mozilla.org/en-US/Add-ons/Overlay_Extensions)[[tag:fiirefox-addon-overlay]]/[[tag:xul]])?请在您的问题中编辑适当的标签。 – Makyen
它似乎是一个WebExtension。如果是这样,请添加适当的标签。 – Makyen
请将[问题]置于主题上:包括一个重复问题的**完整** [mcve]。包括一个* manifest.json *,一些背景*和*内容脚本。寻求调试帮助的问题(“**为什么不是这个代码工作?”)必须包括:►期望的行为,►特定问题或错误*和*►在问题中重现问题所需的最短代码**本身**。没有明确问题陈述的问题对其他读者无益。请参阅:“**如何创建[mcve] **”,[我可以在此处询问哪些主题?](http://stackoverflow.com/help/on-topic)和[问]。 – Makyen