How to save recent searches with javascript?
forms, javascript, jquery, json
Solution
Use HTML5 Local Storage to store and read saved searches.:
// Write a local item..
localStorage.setItem("myKey", "myValue");
// Read a local item..
var theItemValue = localStorage.getItem("myKey");
// Check for changes in the local item and log them..
window.addEventListener('storage', function(event) {
console.log('The value for ' + event.key + ' was changed from' + event.oldValue + ' to ' + event.newValue);
}, false);
// Check for HTML5 Storage..
function supports_html5_storage() {
try {
return 'localStorage' in window && window['localStorage'] !== null;
} catch (e) {
return false;
}
}
Problem
When user perform a search, these search settings should be saved for future use. User should fill some form fields and then perform a search. When he perform a new search, the old one should be able, etc, etc. Im using javascript, jQuery. How could I do this? I mean save it in localmachine, not in database.