将下拉历史记录保存在Firefox工具栏中
为了学习,我正在Firefox工具栏上进行一些测试,但找不到关于如何在用户个人资料中存储"搜索"下拉菜单内容的任何信息。
是否有任何有关如何解决此问题的教程?
解决方案
由于要花很多时间才能得到答案,因此我自己进行了调查。
这就是我现在所拥有的。并非所有人都清楚,但它可行。
假设我们在.xul上具有这样的<textbox>:
<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); }
这是获得历史记录的绝对最小值。
古斯塔沃
我想做同样的事情,在Mozilla支持论坛上找到了答案。 (编辑:我不想引起搜索历史的兴趣,不是因为我想学习Firefox工具栏的工作方式,就像我们所说的那样。)
基本上,这些数据存储在一个名为formhistory.sqlite的sqlite数据库文件中(在Firefox配置文件目录中)。我们可以使用Firefox扩展SQLite Manager来检索和导出数据:https://addons.mozilla.org/firefox/addon/5817
我们可以将其导出为CSV(逗号分隔的值)文件,并使用Excel或者其他软件将其打开。
如果我们感兴趣,还可以保存我们在网站上其他表单/字段中输入的数据的历史记录,例如Google的"搜索"字段等,这还有一个好处。
古斯塔沃(Gustavo)的解决方案很好,但是document.getElemenById('search_with_history')。value;在getElementById中缺少" t"