2008-09-23 23 views

回答

1

,因爲它是採取相當多的得到答案我去調查它自己。 這是我現在得到的。並非所有人都清楚,但它的作品。

讓我們假設你有一個<文本框>這樣,你的.xul:

<textbox id="search_with_history" /> 

現在,您可以添加一些其他的屬性,使歷史。

<textbox id="search_with_history" type="autocomplete" 
    autocompletesearch="form-history" 
    autocompletesearchparam="Search-History-Name" 
    ontextentered="Search_Change(param);" 
    enablehistory="true" 
/> 

這給了你在該文本框中啓用歷史記錄的最小值。
出於某種原因,這裏是我的無知顯示的地方,onTextEntered事件函數必須具有名爲「param」的參數。我嘗試了「事件」,但沒有奏效。
但是,這本身並不會獨自完成工作。必須添加一些Javascript來幫助完成這項工作。

// This is the interface to store the history 
const HistoryObject = Components.classes["@mozilla.org/satchel/form-history;1"] 
    .getService(
     Components.interfaces.nsIFormHistory2 || Components.interfaces.nsIFormHistory 
    ); 
// The above line was broken into 4 for clearness. 
// If you encounter problems please use only one line. 

// This function is the one called upon the event of pressing <enter> 
// on the text box 
function Search_Change(event) { 
    var terms = document.getElementById('search_with_history').value; 
    HistoryObject.addEntry('Search-History-Name', terms); 
} 

這是獲取歷史記錄的絕對最小值。

0

Gustavo, 我想做同樣的事情 - 我在Mozilla支持論壇上找到了一個答案here。 (編輯:我想保存我的搜索歷史出於興趣,而不是因爲我想了解Firefox工具欄是如何工作的,正如您所說的那樣)。

基本上,該數據存儲在名爲formhistory.sqlite的sqlite數據庫文件中(在您的Firefox個人資料目錄中)。您可以使用Firefox擴展SQLite管理器來檢索和導出數據:https://addons.mozilla.org/firefox/addon/5817

您可以將其導出爲CSV(逗號分隔值)文件並使用Excel或其他軟件打開它。

這個也有節省您輸入到網站上的其他形式/領域,如在谷歌等搜索欄的歷史數據,如果這個數據是您感興趣的好處。 。

0

古斯塔沃的解決方案是好的,但document.getElemenById( 'search_with_history')值;中的getElementById缺少一個 'T'

+0

感謝傑森,糾正。下次你可以使用評論而不是答案嗎? – 2009-08-14 01:00:41