2013-10-08 32 views
0

我想寫一個擴展示例以覆蓋javascript提供的一些html內容的新頁面。這個怎麼做 ? JavaScript來提供HTML內容在這裏:如何覆蓋firefox中的新標籤頁

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; 
} 
+0

這是什麼問題?是在查詢歷史記錄服務,還是在新標籤頁上實際獲取HTML? – jsantell

回答

0

要覆蓋NEWTAB頁面,設置browser.newtab.url偏好一些HTML/XUL文件。在文檔中包含任何腳本來填充內容。

但請不要串接續模式的HTML片段在一起,你很可能與不安全的代碼結束了,但使用DOM API,如document.createElement()Node.textContentNode.setAttribute等來代替。