Anonymous
Как создать ссылку, активную в определенное время [закрыто]
Сообщение
Anonymous » 25 окт 2024, 04:46
Мне нужно создать ссылку на HTML-странице, по которой можно будет щелкнуть только в определенное время. У меня есть следующий код, но он, похоже, не работает. Желательно, чтобы ссылка была активна в определенное время и дату. Например, ссылка может быть активной в 10:00 24.10.2024, а затем неактивной либо в определенное время, либо через несколько часов.
Код: Выделить всё
#myButton {
padding: 10px 20px;
background-color: gray;
color: white;
border: none;
text-decoration: none;
display: inline-block;
pointer-events: none;
cursor: not-allowed;
}
#myButton.active {
background-color: blue;
cursor: pointer;
pointer-events: auto;
}
#myButton.disabled {
background-color: red;
cursor: not-allowed;
pointer-events: none;
}
Click the link between 10:00 AM and 10:15 AM Eastern Time
[url=#]Link Disabled[/url]
const easternTimeOffset = -4;
const targetStartDate = new Date();
const targetEndDate = new Date();
targetStartDate.setUTCHours(10 + easternTimeOffset, 0, 0, 0);
targetEndDate.setUTCHours(10 + easternTimeOffset, 15, 0, 0);
const button = document.getElementById("myButton");
function checkTime() {
const now = new Date();
if (now >= targetStartDate && now < targetEndDate) {
button.href = "https://www.britannica.com/science/world-map";
button.classList.add("active");
button.classList.remove("disabled");
button.textContent = "Click Me Now!";
} else if (now >= targetEndDate) {
button.href = "#";
button.classList.remove("active");
button.classList.add("disabled");
button.textContent = "Link Disabled";
}
}
checkTime();
setInterval(checkTime, 1000);
Подробнее здесь:
https://stackoverflow.com/questions/791 ... cific-time
1729820809
Anonymous
Мне нужно создать ссылку на HTML-странице, по которой можно будет щелкнуть только в определенное время. У меня есть следующий код, но он, похоже, не работает. Желательно, чтобы ссылка была активна в определенное время и дату. Например, ссылка может быть активной в 10:00 24.10.2024, а затем неактивной либо в определенное время, либо через несколько часов. [code] #myButton { padding: 10px 20px; background-color: gray; color: white; border: none; text-decoration: none; display: inline-block; pointer-events: none; cursor: not-allowed; } #myButton.active { background-color: blue; cursor: pointer; pointer-events: auto; } #myButton.disabled { background-color: red; cursor: not-allowed; pointer-events: none; } Click the link between 10:00 AM and 10:15 AM Eastern Time [url=#]Link Disabled[/url] const easternTimeOffset = -4; const targetStartDate = new Date(); const targetEndDate = new Date(); targetStartDate.setUTCHours(10 + easternTimeOffset, 0, 0, 0); targetEndDate.setUTCHours(10 + easternTimeOffset, 15, 0, 0); const button = document.getElementById("myButton"); function checkTime() { const now = new Date(); if (now >= targetStartDate && now < targetEndDate) { button.href = "https://www.britannica.com/science/world-map"; button.classList.add("active"); button.classList.remove("disabled"); button.textContent = "Click Me Now!"; } else if (now >= targetEndDate) { button.href = "#"; button.classList.remove("active"); button.classList.add("disabled"); button.textContent = "Link Disabled"; } } checkTime(); setInterval(checkTime, 1000); [/code] Подробнее здесь: [url]https://stackoverflow.com/questions/79123246/how-to-create-a-link-that-is-active-at-a-specific-time[/url]