0

我想编写一个示例扩展来使用 javascript 提供的一些 html 内容覆盖 newtab 页面。这个怎么做 ?Javascript 在此处提供 html 内容:

function getFavouriteWebsite() {

    var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsINavHistoryService);
    var query = historyService.getNewQuery();
    var options = historyService.getNewQueryOptions();
    options.queryType = 0;
    options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
    options.maxResults = 6;
    var result = historyService.executeQuery(query, options);
    result.root.containerOpen = true;
    var contentHtml ='';
    for (var i = 0; i < result.root.childCount; i++) {
        for (var i = 0; i < result.root.childCount; i++) {
            contentHtml += "<p><a href=\"" + result.root.getChild(i).uri + "\">" +               (result.root.getChild(i).title == "" ? result.root.getChild(i).uri : result.root.getChild(i).title) + "</a></p>";
        }
    }
    return contentHtml;
}
4

1 回答 1

0

要覆盖新标签页,请将browser.newtab.url首选项设置为某个 HTML/XUL 文档。在该文档中包含任何脚本以填充内容。

但是请不要将 html 片段字符串连接在一起,因为您可能会得到不安全的代码,而是使用 DOM API,例如document.createElement(),Node.textContentNode.setAttribute

于 2013-10-14T21:17:55.417 回答