Clear form on back button jquery

JQuery

Many of us, want to clear specific fields on going back page via browser back button.

Someone asked:

How do I clear the contact form data when the user clicks back on the browser to prevent spammers submitting the form multiple times by clicking back, submit over and over again?

Actually Modern browsers implement something known as back-forward cache (BFCache). When you hit back/forward button the actual page is not reloaded (and the scripts are never re-run).

So, to achieve it, you need to add code into submit click function, so, before submission just convert that field type into password. see below jquery code.

 


$("#submit").click(function () {
$('.phone').prop("type", "password");
});

 

People also ask for this solution via:

  • refresh page on back button
  • clear form on back button in html
  • browser back button keep input values
  • browser back button loses form data
  • preserve form data back button
  • javascript history back keep form data
  • back forward cache
Clear form on back button jquery
User Rating: 4.1 (1 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

More in Software
email encode php simple
Simple php function to encode(unreadable) and decode(readable) email address.

Dear readers, I needed to improve email security little but needed to create functions to do so. under given are...

Close