Hello, I need to know how query parameters are used to load different versions of a webpage on local server? When I googled “query parameters,” I got a lot of answers about how to use them on the server side. But what am I supposed to do if I only want to change local server (and using vanilla JS) from:
It’s not clear to me how the JS, HTML files work together to make this happen?
you can read the content of the URL bar with
You could read the params with JS and then run different stuff depending on it.
With this you mean a local server instance, like a dev server you use on your machine?
(some example includes webpack dev server, parcel, your own apache…)
Or you mean the browser?
According to this the answer may change.
Sorry, not sure (my knowledge of the mechanics of how webpages work is so weak). But basically, I have a folder with index.html. That HTML file reads in the JS file. Then I run ‘python -m http.server’ which creates my page at localhost:8000. And I view that page in chrome browser.
Does that answer your question?
I created a small example project:
Thanks for that @miku86!
Unfortunately, I need to use query parameters to switch between versions of webpage. So if query parameter returns “configA” and “data_1”, then version A of the page should show and if query parameter returns “configB” and “data_2”, then version B of the page should show.
Is there a way to do that?
that’s why I posted the link to
window.location in my first reply.
There you will find a link to
Location and its property to parse out the parameters from the querystring.