How to launch a google search in a new tab or window from javascript?

前端 未结 4 606
灰色年华
灰色年华 2020-12-09 07:02

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 us

4条回答
  •  孤街浪徒
    2020-12-09 07:41

    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:

    Demo: http://jsfiddle.net/yGCSK/

    If you have the search query in a javascript variable, something like:

    
    
    

    Demo: http://jsfiddle.net/kGBEy/

提交回复
热议问题