duftyr
duftyr

Reputation: 1

Can't find value of 'input' element in JS

I've been messing with YouTube lately, but the search bar confuses me.

If I search something long, like "a;sldjf;asbybytyeu2430572735gljahflg", then control-f in the DOM, the only reference I can find to the search term is in the page title. Even when I look at the 'input' element of the search bar, it doesn't have a 'value' property.

My question is this: How can the browser display text that doesn't appear anywhere in the DOM? Where is the data stored?

Upvotes: 0

Views: 55

Answers (1)

luek baja
luek baja

Reputation: 1674

It is in the URL query string. For example, if I search "dank memes", this is the URL: https://www.youtube.com/results?search_query=dank+memes

It can be accessed by JavaScript with window.location.search which in this case would return "?search_query=dank+memes" But most likely YouTube's JavaScript code does not access it and it is only used to send the information for a GET request to the server. Then the server will display all the needed information.

Upvotes: 1

Related Questions