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