I want an html button with link to be opened after particular time.
For example a button with link www.google.com which would be opened after 04/10/2021 08:30pm 0530 GMT
THANK YOU ALL ..
CodePudding user response:
Perhaps something like this?
HTML:
<button id="my_button" type="button" disabled>Hello World!</button>
Javascript:
var d1 = new Date();
var d2 = new Date('2021-10-05');
if (d1 >= d2) document.getElementById('my_button').disabled = false;
This will compare the two Date() variables and if d1 is equal or greater than d2, it will set the disabled attribute of the button to false.
CodePudding user response:
One way to do it would be to disable the button at first and then using js to enable it when the exact date and time are matched
<button type="button" id="myBtn" disabled">Please wait...</button>
Now we can just use js to first get an object to our button element and then using the Date() constructor to match the exact date and time for our input, enabling the button
var myBtn = document.getElementById('myBtn');
var currenttime = new Date(); //Date object
we can now just use the Date object to get current time in our format nd then remove the disable attribute from the button
if (currenttime === giventime) $("#myBtn").removeAttr("disabled");
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date