禁用Google API WebSearch结果标题中的突出显示

时间:2010-03-05 05:20:04

标签: javascript google-api

我一直在使用Google网页搜索API,但搜索到的关键字会突出显示 - 在返回对象的title属性中使用b tag-。

我认为webSearchControl.setNoHtmlGeneration();可以有效,但没有改变任何内容。

我知道如何处理其他方式,但Google API是否提供了任何方法来避免响应中出现任何html内容?

感谢。

顺便说一下,让我在这里粘贴我的代码以获取更多信息:

google.load("search", "1", { "nocss": true });

function OnLoad() {
    // Create a search control
    var webSearchControl = new google.search.WebSearch();
    webSearchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
    webSearchControl.setNoHtmlGeneration();
    webSearchControl.setSearchCompleteCallback(this, OnCompleted, [webSearchControl]);
    webSearchControl.execute("programming");
    setInterval(function () {
        webSearchControl.execute("Programming");
    }, 3000);

}

function OnCompleted(webSearchControl) {
    var results = webSearchControl.results;
    $("#googleSearch").html($("#googleSearch").html() + '<br/><a href=' + results[0].url + ' target="blank">' + results[0].title + '</a>');
}

google.setOnLoadCallback(OnLoad);

1 个答案:

答案 0 :(得分:1)

我刚刚找到了解决方案:

它应该是这样的:

$("#googleSearch").html($("#googleSearch").html() + '<br/><a href=' + results[0].url + ' target="blank">' + results[0].titleNoFormatting + '</a>');
}

所以基本上.titleNoFormatting解决了这个问题。