Hello can a member tell me about how to link a url with this below code.This code is about to disable button after click for specific time kindly help me how can I add url to this code
<html>
<head>
</head>
<body>
<button id="button">click me</button>
</body>
<script type="text/javascript">
var myButton=document.getElementById("button");
function storeTime(theTime)
{
localStorage.setItem("time", theTime);
}
function check()
{
var now=new Date().getTime();
if(!localStorage.getItem("time"))
{
storeTime(now);
}
var storedTime=parseInt(localStorage.getItem("time"));
if(storedTime>now)
{
myButton.disabled=true;
}
else
{
myButton.disabled=false;
}
}
function buttonClicked()
{
var now=new Date().getTime() + 180000;
storeTime(now);
myButton.disabled=true;
}
setInterval(check, 1000);
check();
myButton.addEventListener("click", buttonClicked);
</script>
</html>
To link a URL with your code so that clicking the button takes the user to a new URL after it’s enabled, you can modify the buttonClicked function to include window.location.href .
This code worked great but the problem is that this code is hackable with date…If we change today’s date to new date then the button become clickable.
The simple answer is that you cant prevent someone from enabling a button you’ve put down; your server-side needs to handle the interaction if you want it to not be bypassable.
What i mean is you cant stop someone from pushing the button. What happens when the button is pushed can be changed.
I dont know what server side language(s) your host is running. PHP? ASP? Python? Node?
Whatever language it is, the abstraction would be basically:
User requests page.
Server makes note of the user, starting a session for them; it notes the time and stores that internally.
Server sends page to the user.
User clicks the button.
Button sends a request to the server to get data (a URL, some data, whatever).
Server looks at the user’s session time, compares it to the server’s current time; if enough time has passed, send the appropriate data. If it hasnt, send an error.
The page’s javascript receives the answer from the server, and acts appropriately.