I have a Google Instant style search script written in jQuery. When the user queries, #SEARCHTERM is added onto my page URL. How can I make it so that my URL is something like #search/SEARCHTERM/1/?
My jQuery code is:
$(document).ready(function(){
$("#search").keyup(function(){
var search=$(this).val();
var query=encodeURIComponent(search);
var yt_url='search.php?q='+query+'&category=web';
window.location.hash=query;
document.title=$(this).val()+" - My Search Script";
if(search==''){
document.title='My Search Script';
}
$.ajax({
type:"GET",
url:yt_url,
dataType:"html",
success:function(response){
$("#result").html(response);
}
});
});
});
You need to alter
window.location.hash=query;so it iswindow.location.hash="search/" + query;You will also need to alter the function that reads it on page load to remove the “search/”. Either use substring() or replace().