the-glorious-startpage/js/search-query-send.js

31 lines
567 B
JavaScript
Raw Normal View History

2020-06-04 05:27:00 +02:00
// Search box
var searchBox = document.getElementById("searchBox");
// Web Search
const webSearch = () => {
// Search
window.location.href = encodeURI(searchQueryPrefix + searchBox.value);
};
// Key release event
searchBox.addEventListener(
"keyup",
(event) => {
// Number 13 is the "Enter" key on the keyboard
if (event.key === 'Enter') {
// Don't accept empty strings
if (searchBox.value < 1) {
return;
}
// Cancel the default action, if needed
event.preventDefault();
// Search the web
webSearch()
};
}
);