0

我正在使用来自谷歌搜索 API 的代码以及我自己的 jquery 函数对控制台进行简单的日志记录,我注意到 jquery 函数被触发了两次。此外,还会抛出 javascript 错误(即使在 Google 的示例页面上也会发生这种情况)。

这是我的代码:

<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

如何解决这些错误并解决双击问题?

4

1 回答 1

1

看起来我做错了 - 做我想做的事情,最好使用 JSON 自定义搜索 API - 此处提供文档:

http://code.google.com/apis/customsearch/v1/overview.html

于 2011-10-25T15:47:51.443 回答