2010-03-05 55 views
0

我一直在使用Google Web搜索API,但搜索關鍵字突出顯示 - 在返回對象的title屬性中帶有b標籤。禁用Google API中的突出顯示Web搜索結果標題

我以爲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

我剛剛找到了解決辦法:

應該是這樣的:

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

所以基本上.titleNoFormatting這裏解決了這個問題。

相關問題