你可能有一個以上的問題,在同一時間發生的事情......
1.查詢參數不匹配
你searchresults-only
上gcse:searchbox-only
指定queryParameterName
不匹配。
的index.html
<gcse:searchresults-only queryParameterName="search"></gcse:searchresults-only>
Search.html
<gcse:searchresults-only queryParameterName="search"></gcse:searchresults-only>
2. Angular.js阻止谷歌CSE
的流動在正常情況下, Google搜索元素將觸發HTTP GET w ith搜索參數。但是,由於您正在處理單頁應用程序,因此您可能看不到查詢參數。如果當你的目標resultsUrl="#/searchresult"
這種懷疑是真的,那麼你有兩個選擇:在resultsUrl =
- 強制HTTP GET 「的http:// YOURWEBSITE /信息搜索結果」。您可能必須匹配路線,或沿着這些線路來捕捉REST請求(Ember.js很容易實現,但我還沒有在Angular.js中完成)。
- 使用JQuery和Angular .js從Index.html上的用戶獲得輸入,並手動觸發search.html上的搜索。你會怎麼做?對於index.html,你會做類似於下面的事情,並且爲了實現類似於我在另一個post中回答的結果。
的Index.html
<div>GSC SEARCH BUTTON HOOK: <strong><div id="search_button_hook">NOT ACTIVATED.</div></strong></div>
<div>GSC SEARCH TEXT: <strong><div id="search_text_hook"></div></strong></div>
<gcse:search ></gcse:search>
Index.js
//Hook a callback into the rendered Google Search. From my understanding, this is possible because the outermost rendered div has id of "___gcse_0".
window.__gcse = {
callback: googleCSELoaded
};
//When it renders, their initial customized function cseLoaded() is triggered which adds more hooks. I added comments to what each one does:
function googleCSELoaded() {
$(".gsc-search-button").click(function() {
$("#search_button_hook").text('HOOK ACTIVATED');
});
$("#gsc-i-id1").keydown(function(e) {
if (e.which == 13) {
$("#enter_keyboard_hook").text('HOOK ACTIVATED');
}
else{
$("#search_text_hook").text($("#gsc-i-id1").val());
}
});
}
(function() {
var cx = '001386805071419863133:cb1vfab8b4y';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
我有index.html的代碼的live version,但我不做出承諾說會因爲它是在我的NDSU FTP中託管的,所以永久生活。