2

Is there any way to access the autocomplete suggestions that appear under HTML input fields in some browsers (representing previously submitted data)? Is this only available to the browser?

I ask as I want to make my own autocomplete implementation in javascript, but I want to intermingle my own suggestions with the users previous searches. A bit like how youtube does (but youtube stores all the data obviously, and it is tied to a login, there are no accounts on my website and never will be).

I was wondering more if there was a way to do it with the data stored in the users browser rather than storing all the data on my server. Is there is a way to grab the data the browser uses to present previous input to a user?

4

3 回答 3

3

出现在 html 输入字段中代表先前提交的数据的数据是否仅对浏览器可用?

是的 - 直到它出现在 DOM 中。

有没有办法获取浏览器用来向用户呈现先前输入的数据?

这是特定于浏览器的功能,您不能直接访问数据 [历史](浏览器在哪里保存/存储自动填充数据)。您只能禁用存储任何内容

我问,因为我想在 javascript 中进行自己的自动完成实现,但我想将我自己的建议与用户以前的搜索混合在一起。我想知道是否有办法使用存储在用户浏览器中的数据而不是将所有数据存储在我的服务器上。

尤其是如果您想利用所有以前的搜索,浏览器的自动填充对您没有任何帮助。但是是的,您可以手动将它们存储在浏览器中(在客户端):使用DOM Storage,例如localStorage. 虽然我sessionStorage只推荐,但如果每个使用浏览器的人都能看到以前用户的搜索词,你可能会遇到隐私问题……</p>

于 2013-07-02T11:46:40.193 回答
0

我看到这个工作的唯一方法是借助localStorage(html5) 问题,它在 ie<8 中不起作用

这是一个例子:http: //jsfiddle.net/8NZY7/

于 2013-07-02T11:54:53.063 回答
0

您可以使用jstorage。Jstorage 允许您在客户端存储多达 5Mb 的数据。

<script src="//cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js"></script>
<script src="https://raw.github.com/andris9/jStorage/master/jstorage.js"></script>
<script> 
/* $.jStorage is now available */ 

// store some data
$.jStorage.set('yourkey', 'whatever value');

// get the data back
value = $.jStorage.get('yourkey');

</script>
于 2013-07-02T11:31:27.340 回答