1

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");
        }
HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
VG98
  • 114
  • 1
  • 12

2 Answers2

1

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>
TakumiTech
  • 35
  • 1
  • 7
0

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

Community
  • 1
  • 1
segFault
  • 3,887
  • 1
  • 19
  • 31