Я пытаюсь создать кнопку, которая ведет на случайную страницу сайта. У меня есть код ниже.
Спасибо.
Homepage
Discover new cars from Legendary Brands such as Ferrari, Mercedes or Your One and Only Bugatti
Click here!
const pages = [
"Mercedes.html",
"Ferrari.html",
"Bugatti.html",
];
const randomLink = document.getElementById("randomLink");
randomLink.addEventListener("click", function(event) {
event.preventDefault(); // Prevent default anchor behavior
const randomIndex = Math.floor(Math.random() * pages.length);
const randomPage = pages[randomIndex];
window.location.href = randomPage; // Redirect to the random page
});
Подробнее здесь: https://stackoverflow.com/questions/791 ... lved-idk-w
Мобильная версия