Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140161

I want to disable the download button after 15 minutes of the updated time. I dont know how to do it [closed]

$
0
0

I recall the updated time time from database. I want to disable the button 15 minutes after the updated time and keep disable even after reload or refresh the page.

<tr>
       <td class="table-user-profile-attribute">
              {% trans 'Updated time' %}
       </td>
       <td>{{ app.updated_time | default:_('Not provided.') }}
       </td>
</tr>
<button id="myButton"
         style="border-radius: 50px; width: 130px;" type="button"
         class="btn btn-primary btn-cons m-b-10 pull-right">
         <i class="fa fa-download"></i>&nbsp;&nbsp;<span
         class="bold">{% trans "Download" %}</span>
</button>

I have tried this in javascript. But this not compared the time with the updated time in the database.

<script>
$(document).ready(function(){
   var limit = 15*60*1000; // the time limit (in milliseconds) for the disable function
   var timer = setTimeout(disableMyButton, limit);

   function disableMyButton(){
      $('#myButton').prop('hidden', true);
      localStorage.setItem("isMyButtonDisabled", "true");
   }

   if(localStorage.getItem("isMyButtonDisabled") == "true"){
     $('#myButton').prop('hidden', true);
     window.clearTimeout(timer);
   }
});
</script>

This is my model of application.

class Application(models.Model):
created_at = models.DateTimeField(auto_now_add='True')
updated_at = models.DateTimeField(
        auto_now='True', blank='True', null='True')

Viewing all articles
Browse latest Browse all 140161

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>