为了学习,我正在对Firefox工具栏进行一些测试,但我找不到有关如何存储<!>“搜索<!>”内容的任何信息。在用户个人资料中下拉。

有没有关于如何解决这个问题的教程?

有帮助吗?

解决方案

由于我需要花很多时间才能得到答案,所以我自己去调查一下。 这就是我现在所拥有的。并非所有人都清楚,但它确实有效。

假设你有一个<!> lt; textbox <!> gt;像这样,在.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事件函数必须有一个名为<!> quot; param <!> quot;的param。我试过<!> quot; event <!> quot;它不起作用。
但仅凭这一点本身并不起作用。一个人必须添加一些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);
}

这是历史记录的最低限度。

其他提示

古斯塔沃, 我想做同样的事情 - 我找到了答案 https://addons.mozilla .ORG /火狐/插件/ 5817

您可以将其导出为CSV(逗号分隔值)文件,并使用Excel或其他软件将其打开。

如果您对此数据感兴趣,还可以将您输入的数据的历史记录保存到网站上的其他表单/字段(如Google上的搜索字段等)中,这样做还有额外的好处。

Gustavo的解决方案很好,但是 document.getElementById('search_with_history')。value; 在getElementById中缺少't'

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top