23/04/2010, 01:17:10
Voilà ton code, il est paramétré selon tes besoins montrés plus haut (tu n'as qu'à rajouter les {literal}) :
page avec le form
page résultats :
page avec le form
Code :
<head>
<script type="text/javascript">
function inputFocus() {
document.getElementById('query-input').style['background'] = '';
}
function inputBlur() {
var queryInput = document.getElementById('query-input');
if (!queryInput.value) {
queryInput.style['background'] = 'white url(http://www.google.com/coop/images/google_custom_search_watermark.gif) no-repeat 0% 50%';
}
}
</script>
</head>
<body onload="inputBlur();">
<form action="/index.php?page=recherche" method="GET">
<input name="q" size="50" id="query-input" onfocus="inputFocus();" onblur="inputBlur();" />
<button type="submit">Search</button>
</form>
Code :
<head>
<title>Résultat de la recherche</title>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1');
/**
* Extracts the users query from the URL.
*/
function getQuery() {
var url = '' + window.location;
var queryStart = url.indexOf('?') + 1;
if (queryStart > 0) {
var parts = url.substr(queryStart).split('&');
for (var i = 0; i < parts.length; i++) {
if (parts[i].substr(0, 1) == 'q') {
return unescape(parts[i].split('=')[1].replace(/\+/g, ' '));
}
}
}
return '';
}
function onLoad() {
var customSearchControl = new google.search.CustomSearchControl(
'http://www.coord21.ch/test_cmsms');
// Draw the control in content div
customSearchControl.draw('cse-search-results');
// Run a query
customSearchControl.execute(getQuery());
}
google.setOnLoadCallback(onLoad);
</script>
</head>
<body>
<div id="cse-search-results">Votre recherche est en cours...</div>