有什么方法可以从JavaScript访问浏览器表单字段建议? [英] Is there any way to access browser form field suggestions from JavaScript?
问题描述
在某些浏览器中,有什么方法可以访问显示在HTML输入字段下的自动完成建议(代表以前提交的数据)?这仅适用于浏览器吗?
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?
我问是因为我想用javascript来实现自己的自动完成功能,但是我想将自己的建议与用户以前的搜索混在一起.有点像youtube的操作方式(但youtube显然存储了所有数据,并且它与登录名相关联,我的网站上没有帐户,而且永远也不会).
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?
推荐答案
出现在表示以前提交的数据的html输入字段中的数据仅对浏览器可用吗?
Is the data that appears in html input fields representing previously submitted data only available to the browser?
是-直到它出现在DOM中.
Yes - until it appears in the DOM.
有没有办法获取浏览器用来向用户呈现先前输入的数据?
Is there is a way to grab the data the browser uses to present previous input to a user?
这是特定于浏览器的功能,您无法直接访问数据[历史记录](浏览器在哪里保存/存储自动填充数据).您只能禁用存储任何内容.
It's a browser-specific feature, and you can't access the data [history] directly (Where do browsers save/store auto fill data). You only can disable storing anything.
我问是因为我想用javascript来实现自己的自动完成功能,但是我想将自己的建议与用户以前的搜索混在一起.我想知道是否还有办法处理存储在用户浏览器中的数据,而不是将所有数据存储在服务器上.
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. 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.
尤其是如果您想利用以前的所有搜索功能,浏览器的自动填充功能仍然无法为您提供帮助.但是可以,您可以将它们手动存储在浏览器中(在客户端):使用
Especially if you want to utilize all previous searches, the browser's autofill doesn't help you anyway. But yes, you can store them in the browser (on the client side) manually: Use DOM Storage, like localStorage
. Though I would recommend sessionStorage
only, you might run into privacy issues otherwise if everybody using a browser could see the search terms of previous users…
这篇关于有什么方法可以从JavaScript访问浏览器表单字段建议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!