2013-11-15 62 views
0

我在我的HTML文件中有这个Java脚本....我有一个关键字搜索我的网页,我想通过关键字搜索到API。这是我目前拥有的:不确定我出错的地方,它没有产生任何搜索结果。谷歌新闻Api自定义搜索

,我在代码中有

CNN 

,这是我的搜索变量应该传递...

<script type="text/javascript"> 

    google.load('search', '1'); 

    function OnLoad() 
    { 
     var customSearchControl = new google.search.CustomSearchControl('CNN'); 
     customSearchControl.setResultSetSize(google.search.Search.FILTERED_ 
                  CSE_RESULTSET); 
     customSearchControl.draw('cse'); 
     customSearchControl.execute("$q"); 
    } 
    google.setOnLoadCallback(OnLoad); 

    // tell the searcher to draw itself and tell it where to attach 
     // create a drawOptions object 
     var drawOptions = new google.search.DrawOptions(); 

     // tell the searcher to draw itself in tabbed mode 
     drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED); 
     searchControl.draw(document.getElementById("content"),drawOptions); 

     searchControl.addSearcher(new google.search.NewsSearch()); 
    } 

    google.setOnLoadCallback(OnLoad); 

    </script> 

回答