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?

Paul D. Waite
  • 89,393
  • 53
  • 186
  • 261
danbroooks
  • 2,477
  • 4
  • 18
  • 39
  • Do you mean input which the user has submitted to your server previously? It should be easy to keep track of that. – Uooo Jul 02 '13 at 10:56
  • Yes, this is a browser feature. Though you can wait for `onload` and just access the input's `.value` properties – Bergi Jul 02 '13 at 10:58
  • 1
    @DanBrooks: Please put this information from the comment into the question, it looks like an [XY Problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) otherwise – Bergi Jul 02 '13 at 11:16

3 Answers3

3

Is the data that appears in html input fields representing previously submitted data only available to the browser?

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.

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…

Community
  • 1
  • 1
Bergi
  • 513,640
  • 108
  • 821
  • 1,164
  • `Especially if you want to utilize all previous searches, the browser's autofill doesn't help you anyway.` Do you mean 'all' as in everyone's (all visitors) or all as in including the user's searches after browser autofill history has been wiped? I want to access the specific user's autofill info, if it is cleared I am happy for it to be cleared on my site aswell. – danbroooks Jul 02 '13 at 11:55
  • I meant the latter, but it could be either :-) My point was that it's impossible to access the *full* history, you only might get the one (topmost?) item that is automatically filled in on page load (though I'm not sure whether all browsers do that at all). – Bergi Jul 02 '13 at 12:11
  • Could you elaborate on what you said with regards to `localStorage` having privacy issues? `localStorage` seems to be the route I will go down as `sessionStorage` is wiped at the end of the session. – danbroooks Jul 02 '13 at 13:21
0

You can use jstorage. Jstorage lets you store up to 5Mb of data on the client side.

<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>
Drew
  • 3,647
  • 3
  • 20
  • 37
0

The only way i see this working is with help of localStorage (html5) problem that it doesn't work in ie<8

Here's an example: http://jsfiddle.net/8NZY7/

Marcio
  • 564
  • 4
  • 20