Files
driftywinds.github.io/js/index.js
2023-04-27 20:27:37 -07:00

16 lines
421 B
JavaScript

const textField = document.querySelector("input");
textField.addEventListener("keypress", function (event) {
// If the user presses the "Enter" key on the keyboard
if (event.key === "Enter") {
event.preventDefault();
const url = textField.value;
const urlRegex = /(https?:\/\/[^ ]*)/g;
if (!url.match(urlRegex))
alert("Invalid URL.");
else
window.location.replace(`home.html?source=${url}`);
}
});