Run function only once

Asked

Viewed 595 times

-2

At first, I’ve seen some similar questions around here, but virtually none of them fit/don’t work in my scenario. It is as follows: I need a script to be executed (in my case, a button to be automatically clicked) only once (possibly by recording a cookie, I believe...) when a user accesses the page in question and disables that same script for any subsequent page access or refresh. How can I proceed?

  • 2

    It is possible to do this using cookies or the localStorage. But it is possible to clear this data and the button be activated again.

1 answer

1

Save to the database if it clicked or not. If you want it to never press the button is necessary to save in the database because cookies can be deleted, the user can access from another computer. In its place I would make a table that would store 0 or 1, if it is 0 it is because n clicked, if it has 1 then it already clicked, then I would not even put the HTML of the button in the page or I would put a disabled on the button.

  • 1

    Thanks for the feedback, Daniel! I got it now! Hugs!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.