我想写一个示例扩展,用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;
}发布于 2013-10-15 05:17:55
要覆盖新选项卡页面,请将browser.newtab.url首选项设置为某个HTML/XUL文档。包括用于填充内容文档中的任何脚本。
但请不要将html片段串连在一起,因为这样可能会以不安全的代码结束,而应使用DOM,如document.createElement()、Node.textContent、Node.setAttribute等。
https://stackoverflow.com/questions/19242683
复制相似问题