将变量传递给Google自定义搜索引擎 [英] Pass variable to Google Custom Search Engine

查看:53
本文介绍了将变量传递给Google自定义搜索引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将搜索变量传递到我嵌入到我的网站中的Google自定义搜索引擎中?我可以使搜索引擎正常工作,但无法通过POST传递术语(它来自网站其他页面上的搜索按钮)

Is it possible to pass a search variable into the Google Custom Search Engine that I have embedded on my website? I can get the search engine to work, but I can't pass it a term via POST (it's coming from a search button on other pages of the website)

我试图破解在这里找到的代码: http: //code.google.com/apis/ajax/playground/?exp=search#hello_world

I tried to hack the code I found here: http://code.google.com/apis/ajax/playground/?exp=search#hello_world

这是我到目前为止所拥有的...($ q是我要传递给它的术语)

And this is what I have so far... ($q is the term I am passing to it)

<script type="text/javascript">
    google.load('search', '1', {language : 'en'});

    function OnLoad()
    {
        var customSearchControl = new google.search.CustomSearchControl('***my key****');
        customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
        customSearchControl.draw('cse');
        searchControl.execute("$q");
    }
    google.setOnLoadCallback(OnLoad);
</script>   

谢谢

推荐答案

对不起,我知道这是一个糟糕的答案,但是除了引用错误的变量名之外,您实际上已经获得了正确的答案.哦,顺便说一句,我也希望您对$ q进行某种消毒,以防有人在您的表单中张贴这样的内容:term); alert(" aha!

Sorry, I know it's a crappy answer, but you've actually got it right apart from referencing the wrong variable name. Oh, also, as an aside, I would also hope you're doing some kind of sanitisation on $q, in case someone posted something like this to your form: term"); alert("aha!

    customSearchControl.draw('cse');
    searchControl.execute("$q");

应为:

    customSearchControl.draw('cse');
    customSearchControl.execute("$q");

此外,谢谢您提出的问题-我一直在寻找自己的方法!

Also, thank you for the question - I was looking for how to do this myself!

这篇关于将变量传递给Google自定义搜索引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆