2

I have a word in the web app. Let's say the word is food. Now, if the user clicks on the word, the Google search screen should open with the results of the word food searched.

enter image description here

I can redirect the user to the Google search screen with the help of

    let win1 = window.open("//" + "google.com", '_blank');

But I am struggling to figure out how to pass the word in the search. Any suggestions on how to go about it?

2 Answers 2

4

Try something like this, with term being a variable with what is being searched (i.e. food)

let win1 = window.open("//" + "google.com/search?q=" + term, '_blank');
Sign up to request clarification or add additional context in comments.

1 Comment

Woah. And talk about simple things in life. Thanks! I was trying to figure out what google searches and somehow the URL constructed was very complicated.
1

Google accepts to search text using Parameter q=. You can just concat this parameter into your URL and try

var searchText = 'food'
let win1 = window.open("//" + "google.com/search?q=" + searchText, '_blank');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.