Say I have a Javascript variable containing a couple of search terms separated by spaces, is it possible to start a Google Search window or tab using these terms (after a user clicks on a button for example)? If yes, does anyone have a simple code example to inject in a HTML?
The google search URL is basically: https://www.google.com/search?q=[query]
Using that you can easily build a search URL to navigate to, f.ex using a simple form without javascript:
<form action="http://google.com/search" target="_blank">
<input name="q">
<input type="submit">
</form>
Demo: http://jsfiddle.net/yGCSK/
If you have the search query in a javascript variable, something like:
<button id="search">Search</button>
<script>
var q = "Testing google search";
document.getElementById('search').onclick = function() {
window.open('http://google.com/search?q='+q);
};
</script>