尝试使用javascript window.location.href向Google发送查询

时间:2013-03-29 17:43:36

标签: javascript

我正在尝试使用javascript向Google发送查询,但该窗口只是转到主页。

这是我的代码:

var query = "hello world";
var firstPart = "http://google.com/?=";
window.location.href = firstPart + query;

页面的URl是正确的,但它不会转到结果。

1 个答案:

答案 0 :(得分:2)

变化:

var firstPart = "http://google.com/?=";

要:

var firstPart = "http://google.com/search?q=";

使用他们的Search Protocol

https://developers.google.com/search-appliance/documentation/62/xml_reference