I would like to on the reload of my page, set my value search (stock in localStorage) in an input and after that simulate a keypress (type 13).
Here is my code :
$( function () {
if( (localStorage.getItem("search")) && (sessionStorage.getItem("reloadAfterPageLoad")!="false") )
{
$('#datatable_filter input').val(localStorage.getItem("search")).focus().trigger(jQuery.Event('keypress', { keycode: 13, which: 13, charCode: 13 }));
}
});
The focus() works as the localStorage.getItem("search") but my event never happens.
I already try the solution of Definitive way to trigger keypress events with jQuery :
$( function () {
if( (localStorage.getItem("search")) && (sessionStorage.getItem("reloadAfterPageLoad")!="false") )
{
var e = jQuery.Event("keypress");
e.which = 13;
alert( "la recherche était : "+localStorage.getItem("search"));
$('#datatable_filter input').val(localStorage.getItem("search")).focus().trigger(e);
sessionStorage.setItem("reloadAfterPageLoad", "false");
}
And it also don't works.
Any idea about the problem ? Thanks in advance for you help