VG98
VG98

Reputation: 114

Google search in HTML?

I want to search in google the value of x. It doesn't work with this code:

function func2(){
            var x = document.getElementById("gsearch").innerHTML;
            window.open("http://www.google.com/#q="+x,"_self");
        }

Upvotes: 1

Views: 403

Answers (2)

TakumiTech
TakumiTech

Reputation: 45

Sorry for posting in a old question. You can do that with the <form> tag.

<form action="https://www.google.com/search">
  <input type="search" name="q">
  <input type="submit" value="Search">
</form>

Upvotes: 1

segFault
segFault

Reputation: 4054

Maybe you want to open a new tab with a Google Search?

Something like:

function func2() {
  var x = document.getElementById("gsearch").value;
  OpenInNewTab("http://www.google.com/custom?q=" + x);
}

function OpenInNewTab(url) {
  var win = window.open(url, '_blank');
  win.focus();
}

Plunker

New Tab via JS Reference

Upvotes: 0

Related Questions