I am wondering if I could store variables in a URL. For example, would https://example.com/?q=Text%20Goes%20Here
be the same as var q = "text goes here";
? Because I have seen some websites do this. For a popular example, youtube. instead of https://www.youtube.com/watch/AgT1MkFjhO4
its https://www.youtube.com/watch?v=AgT1MkFjhO4
. Can I do this?
Asked
Active
Viewed 362 times
0

BreakLikesCoding
- 17
- 7
-
1That's called [query string](https://en.wikipedia.org/wiki/Query_string). And it's not storing variables directly in the URL. Instead it's storing key value pairs in the URL, which the application can then read and convert to the appropriate object structure. And most web applications support it. You haven't described what sort of app yours is, so it's hard to give anything other than general advice. – mason Oct 12 '21 at 23:16
-
sorry for getting back to you late mason! Thanks for your answer! I am using a HTML application if that's what you mean. – BreakLikesCoding Oct 13 '21 at 18:35
-
You're saying variables - what variables? HTML itself has no variables. Are you doing writing JavaScript on your webpage? Please explain your use case more clearly. – mason Oct 13 '21 at 21:53
-
Sorry! I am using JavaScript. – BreakLikesCoding Oct 14 '21 at 12:02
-
Is it a precalled variable? Or do I need to setup up like this `var example = document.title` or something – BreakLikesCoding Oct 14 '21 at 12:05
-
Okay. So you want to use JavaScript to get and or set query string variables? Then you should *search* for that. One of the most important skills for a developer is learning how to research things they don't know about. That means you need to formulate your question carefully, then plug it into Google and examine the results. If you did, you'd find [this question](https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript). – mason Oct 14 '21 at 12:47
-
thank you for helping! – BreakLikesCoding Oct 15 '21 at 17:26