IT, Programming, & Web Development › Forums › Web Development › HarvardX: CS50W – CS50’s Web Programming with Python and JavaScript › CS50W – Lecture 0 – HTML and CSS › Google Search: Why type hidden for image search but not for general web search
- This topic is empty.
-
AuthorPosts
-
June 27, 2024 at 6:55 am #2793
Google Search: Why type hidden for image search but not for general web search
byu/DigitalSplendid incs50[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”markup” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
<!DOCTYPE html> <html lang="en> <head> <title> "Google Search" </title> <link rel="stylessheet" href="styles.css" </head> <body> <form action="https://google.com/search"> <input name="q" type="text" /> <input type="submit" value="Google Search" /> </form> </body> </html>
[/dm_code_snippet]
Source: https://cs50.harvard.edu/web/2020/projects/0/
While trying to create another .html page for Google Image search, took help of an AI that suggested this code:[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”markup” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Google Image Search</title> <link rel="stylesheet" href="styles.css"> </head> <body> <form action="https://www.google.com/search" method="GET"> <input type="hidden" name="tbm" value="isch"> <input type="text" name="q" placeholder="Search images..." /> <input type="submit" value="Google Image Search" /> </form> </body> </html>
[/dm_code_snippet]
I understand GET usage is optional in the above code as GET method is the default.
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”markup” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]<input name="tbm" type="hidden" value="isch" /> <input name="q" type="text" placeholder="Search images..." />
[/dm_code_snippet]
Unable to figure out why hidden type needed for image search but not for general web search on Google Search. So an explanation of the above two lines of code will be helpful.ChatGPT:
The difference between using a hidden input field (
<input type="hidden">
) and a visible input field (<input type="text">
) in the context of Google Search versus Google Image Search lies in how Google processes search queries based on thetbm
parameter.Explanation:
- General Web Search (
tbm
not specified):
- For a general web search on Google, you typically don’t need to specify the
tbm
parameter. When a user submits a search query through a form like<input type="text" name="q" />
, the browser sends the query as part of the URL parameters using the defaultGET
method. Google’s search engine interprets this query as a standard web search by default. -
Example URL: `https://www.google.com/search?q=your_search_query`
- Google Image Search (
tbm=isch
specified):
-
When you want to perform a Google Images search, you need to specify the
tbm=isch
parameter. This tells Google’s search engine that the query is intended for images. By including<input type="hidden" name="tbm" value="isch" />
in your form, you ensure that the search is directed to Google Images rather than the default web search. -
Example URL: `https://www.google.com/search?tbm=isch&q=your_image_search_query`
Why Use
<input type="hidden">
fortbm=isch
?-
Purpose: The hidden input field
<input type="hidden" name="tbm" value="isch" />
is used to specify the type of search (images in this case) directly within the form submission. It ensures that Google processes the search query as an image search, regardless of what the user enters in the visible text input field (<input type="text" name="q" />
). -
Consistency: By including
tbm=isch
as a hidden input, you maintain consistency and predictability in how search queries are processed by Google. This is particularly important when you want to ensure users are directed to the correct type of search results (images vs. web pages). -
User Experience: It simplifies the user experience by guiding users directly to the intended search results without them needing to manually navigate or select the search type on Google’s site.
Conclusion:
In summary, while you don’t need a hidden input field for a general web search (as Google defaults to web search), specifying
tbm=isch
as a hidden input ensures your form directs users to Google Images search results specifically. This approach leverages the hidden field to control the type of search performed, enhancing usability and directing users to the most relevant content based on their query. - General Web Search (
-
AuthorPosts
- You must be logged in to reply to this topic.