I see a lot of ways and a number of them seem overly complicated. i do plan on appending a program that will use these parameters to test based on the results.
But for now, I want a way to get all the URL parameters and post them using a p tag.
I see a lot of ways and a number of them seem overly complicated. i do plan on appending a program that will use these parameters to test based on the results.
But for now, I want a way to get all the URL parameters and post them using a p tag.
Does this answer your question? You can get the search params of a URL with the URL
constructor and accessing the searchParams
property.
const div = document.querySelector('div');
const appendParams = (url) => {
const params = Object.fromEntries(new URL(url).searchParams.entries());
for (const key in params) {
const p = document.createElement('p');
p.textContent = `${key}: ${params[key]}`;
div.appendChild(p);
}
};
window.addEventListener('DOMContentLoaded', () => {
appendParams('https://hello.world?foo=bar&fizz=buzz&abc=123&hello=world');
});
<div></div>