Skip to content

Instantly share code, notes, and snippets.

@ByteJoseph
Created July 8, 2024 15:28
Show Gist options
  • Save ByteJoseph/06a8386c6e1f7048cc98197760071f31 to your computer and use it in GitHub Desktop.
Save ByteJoseph/06a8386c6e1f7048cc98197760071f31 to your computer and use it in GitHub Desktop.
Navigate to Google when hit enter
document.addEventListener('DOMContentLoaded', () => {
const textBox = document.getElementById('your_id');
textBox.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
const keyword = textBox.value;
const googleSearchUrl = `https://www.google.com/search?q=${encodeURIComponent(keyword)}`;
window.location.href = googleSearchUrl;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment