Reputation: 55
Here's my javascript part:
function dateCheckThree()
{
var d = new Date();
var n = d.getDay()
var lukeTre = document.getElementById("Luke3");
if (n === 2)
{
lukeTre.href="home.html";
confirm("Sorry, you gotta wait untill 3.Desember to enter this page.")
}
}
this is my html part:
<a href="Luke3.html" id="Luke3" onClick="dateCheckThree()">
<div-1c> 3 </div-1c>
</a>
NOTE: The Javascript sentenece is true just for testing purposes. When i click the link, I get directed to Luke3.html
Upvotes: 1
Views: 130
Reputation: 2022
Prevent the default behavior of anchor tag as :
function dateCheckThree(e)
{
var d = new Date();
var n = d.getDay()
var lukeTre = document.getElementById("Luke3");
if (n === 2 )
{
e.preventDefault();
alert("Sorry, you gotta wait untill 3.Desember to enter this page.")
lukeTre.href="home.html";
}
}
Upvotes: 2
Reputation: 12391
You need to confirm before redirect, and get the value if you want to confirm.
But i think, you want to use alert
not confirm
.
var redirect = confirm("Sorry, you gotta wait untill 3.Desember to enter this page.");
if (redirect) {
lukeTre.href = "home.html";
}
So I think, what you want something like this (overwrite the condition):
if (n === 2) {
lukeTre.href = "home.html";
} else {
alert("Sorry, you gotta wait untill 3.Desember to enter this page.");
}
Upvotes: 0