首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在firefox中覆盖新标签页

如何在firefox中覆盖新标签页
EN

Stack Overflow用户
提问于 2013-10-08 16:26:24
回答 1查看 692关注 0票数 0

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

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

发布于 2013-10-15 05:17:55

要覆盖新选项卡页面,请将browser.newtab.url首选项设置为某个HTML/XUL文档。包括用于填充内容文档中的任何脚本。

但请不要将html片段串连在一起,因为这样可能会以不安全的代码结束,而应使用DOM,如document.createElement()Node.textContentNode.setAttribute等。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19242683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档