js alarm go to url code example
Example 1: js alarm go to url
function goUrlAlarm(time = '01:02:03', url) {
const today = new Date();
const month = today.getUTCMonth() > 9 ? today.getUTCMonth() : '0' + today.getUTCMonth();
const day = today.getUTCDate() > 9 ? today.getUTCDate() : '0' + today.getUTCDate();
const year = today.getUTCFullYear();
const second = today.getSeconds();
const minute = today.getMinutes();
const hour = today.getHours();
const x = new Date(`${year}-${month}-${day}T${time}`);
const y = new Date(`${year}-${month}-${day}T${hour}:${minute}:${second}`);
setTimeout(function () {
location.href = url;
}, x-y);
}
goUrlAlarm('12:00:00', 'http://google.com');
Example 2: js alarm go to url
function goUrlAlarm(time = '01:02:03', url) {
const today = new Date();
const month = today.getUTCMonth();
const day = today.getUTCDate();
const year = today.getUTCFullYear();
const x = new Date(`${year}-${month}-${day}T${time}`);
const t = new Date(x) - new Date();
setTimeout(function () {
location.href = url;
}, t);
}
goUrlAlarm('12:00:00', 'http://google.com');