直升机,
我正在创建 Google cse 功能进行搜索。使用此代码脚本不设置查询字符串。它无尽的刷新页面。也许有人知道他做对了吗?我只需要每个搜索不同的页面,例如: http : //page.com/search?q=first+search 我可以用 parseParamsFromUrl 函数以某种方式做到这一点吗?
<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'en', style : google.loader.themes.MINIMALIST});
google.setOnLoadCallback(function(){
var cse = new google.search.CustomSearchControl('13707349811359660237:cl5vrpn6mu8');
cse.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
cse.draw('cse');
cse.setNoResultsString('No results for this query, try a different search.');
cse.setSearchStartingCallback({}, function() {
var q = cse.getInputQuery();
window.location.search = '?q='+q;
});
Function parseParamsFromUrl() {
var params = {};
var parts = window.location.search.substr(1).split('\x26');
for (var i = 0; i < parts.length; i++) {
var keyValuePair = parts[i].split('=');
var key = decodeURIComponent(keyValuePair[0]);
params[key] = keyValuePair[1] ?
decodeURIComponent(keyValuePair[1].replace(/\+/g, ' ')) :
keyValuePair[1];
}
return params;
}
var urlParams = parseParamsFromUrl();
var queryParamName = "q";
if (urlParams[queryParamName]) {
cse.execute(urlParams[queryParamName]);
}
}, true);
</script>
任何帮助将不胜感激