Created
January 28, 2020 23:13
-
-
Save thegulshankumar/704866966be96c2f338d9b21d0684f7c to your computer and use it in GitHub Desktop.
Display Search Results Query in Heading and Title
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
const queryString = window.location.search; | |
const urlParams = new URLSearchParams(queryString); | |
const searchTerm = urlParams.get('q'); | |
if (searchTerm) { | |
const heading = document.querySelector('h1'); | |
const title = document.querySelector('title'); | |
heading.textContent = `Search Results for ${searchTerm}`; | |
title.textContent = `Search Results for ${searchTerm}`; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment