script js pour recherche par moteur externe

This commit is contained in:
Tykayn 2024-11-16 00:44:19 +01:00 committed by tykayn
parent 530b8b7553
commit c20b6a1b4d
10 changed files with 78 additions and 9 deletions

View file

@ -0,0 +1,16 @@
// search bar to send a request to a search engine for the current domain when sent
document.addEventListener('DOMContentLoaded', function() {
// Obtient le nom de domaine de la page courante
const currentDomain = window.location.hostname;
const form = document.getElementById('recherche');
// Ajoute un écouteur d'événement pour l'événement 'submit'
form.addEventListener('submit', function(event) {
// Empêche le comportement par défaut du formulaire
event.preventDefault()
const query = document.getElementById('query').value
const url = `https://duckduckgo.com/?q=${encodeURIComponent(query)}+site%3A${encodeURIComponent(currentDomain)}`;
window.location.href = url;
});
});