2011-10-25 36 views
0

我使用谷歌搜索API的代碼以及我自己的jquery函數做一個簡單的日誌到控制檯,我注意到jQuery的功能正在觸發兩次。此外,JavaScript錯誤正在拋出(這甚至發生在Google的示例頁面上)。javascript/jQuery的 - 谷歌自定義搜索API - 功能觸發兩次

這裏是我的代碼:

<script type="text/javascript"> 
     google.load('search', '1', {language : 'en'}); 
     google.setOnLoadCallback(function() { 
      var customSearchControl = new google.search.CustomSearchControl('000638822871137547098:_xxgiq7wt_k'); 
      var linkTarget = "frame"; 
      //customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); 
      //customSearchControl.draw('cse'); 

      // Use "mysite_" as a unique ID to override the default rendering. 
      google.search.Csedr.addOverride("mysite_"); 
      customSearchControl.setLinkTarget(linkTarget) 
      // Draw the Custom Search Control in the div named "CSE" 
      customSearchControl.draw('cse'); 

      $('.gsc-search-button').click(function(){ 
       console.log('click'); 
      }) 

      // Execute an initial search 
      //customSearchControl.execute("ajax"); 


     }, true); 
    </script> 

,這裏是發生了JavaScript錯誤:

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL http://www.google.com/cse?q=x&client=google-coop&hl=en&r=s&cx=000638822871137547098%3A_xxgiq7wt_k&oe=UTF-8&ie=UTF-8&format=n4&ad=n0&adsafe=high&nocache=1319551264502&fexp=20606&num=0&safe=off&output=uds_ads_only&source=gcsc&v=3&adext=as1%2Csr1&rurl=http%3A%2F%2Flocalhost%3A8888%2F#slave-1-1. Domains, protocols and ports must match. 

最後,這裏是從谷歌代碼的例子:

http://code.google.com/apis/customsearch/docs/js/rendering.html#_intro_CSC

怎麼辦我解決了這些錯誤並解決了雙擊問題?

回答