Query string parameters are added to website URLs when using tracking URLs to track a visit from a particular source and campaign or passing correct values in the URL to display desired data and information.
In addition, they are also used in some systems CMS external files to display specific content on a page. With that in mind, we will be teaching you here at Coliseu Geek a simple and quick way to display content on a page using a query string in the URL! Check out!
<div id="content"></div> <script> // Get the value of the "content" parameter from the URL query string const urlParams = new URLSearchParams(window.location.search); const content = urlParams.get('content'); // Display the content on the page document.getElementById('content').innerHTML = content; </script>
Note that this script assumes the content parameter contains text plain. If you want to display the HTML content of the query string, you need to make sure to clean and escape the input to prevent XSS attacks.