user2055929
user2055929

Reputation:

Edit and search an URL with JS

I'm trying to make an easy google chrome extension that gets a string from a textbox and adds it to an URL (ie "https://www.google.com/search?q=") and then google the URL+ input string. How should i make it?

i must say that i'm a beginner, i was thinking of a function that reads the input from the textbox and adds it to the URL. something like this: var google = "google.com/search?q=" + textbox

Upvotes: 1

Views: 153

Answers (2)

Antoine
Antoine

Reputation: 2807

Something like this maybe ?

Getting the content of the textbox (assuming the target input has a textbox id ofc):

var query = document.getElementById('textbox').value

Redirection:

window.location.href = 'https://www.google.com/search?q=' + query

I'm not quite sure of what you'd exactly like though.

Upvotes: 1

Ido Green
Ido Green

Reputation: 2813

You can use the omnibox api in order to get what you need. I've wrote a detailed explanation on this solution here: http://greenido.wordpress.com/2013/03/28/chrome-extension-for-enterprise-internal-usage/

Btw, I hope you gave google.com search just as an example... because it's the default behavior :)

Upvotes: 0

Related Questions