{{error}}
{{(quickSearchResults.length>10)?'10+':(quickSearchResults.length)}} {{(quickSearchResults.length==1)?'result':'results'}}
{{result.title}} {{result.timeStamp | mysql2ymd }}
I am sorry, no such article was written yet.
Sending dynamic client-side parameters in URL fragments and manipulating them
Sending dynamic client-side parameters in URL fragments and manipulating them
Seldom I was in need to perform client filtering on tables and other data, and eventually save the filter. One solution was sending the filter to the server and generate the filtered page.
The functions below (I am using them few years already in Internet Explorer) are used to store and get the properties from fragments.
Some useful clues:
  • When the page is loaded, check all the fragment parameters and update the controls and perform filtering, etc.;
  • Whenever you update a filter in a text field, etc., you can save it in the fragment;
  • You can send the link with fragment to anybody else, and if the first bullet (filter executed on page loading) is accomplished, the URL receiver will see the same page as you.
getFragmentValues.js
function getFragmentValues(){
	var args=document.location.hash;
	if(args)
		args=args.split("#")[1].split(",");
	else args=[];
	var results={};
	for(var i=0;i<args.length;i++){
		var kv=args[i].split("=");
		var k=unescape(kv.shift());
		results[k]=unescape(kv.join("="));
	}
	return results;
}
function getFragmentValue(name,defaultValue){
	var result=getFragmentValues()[name];
	if(result==null)
		result=defaultValue;
	return result;
}
function setFragmentValue(name,value){
	var values=getFragmentValues();
	values[name]=value;
	var result=[];
	for(var l in values)
		if(values[l]!='')
			result.push(escape(l)+'='+escape(values[l]));
	document.location.hash=result.join(",");
}