jQuery get parameter of url after #hash tags

For url that is also document’s location, use below code to find if #hash tag exist

if(window.location.hash) {
	var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
	if( hash){
		//do something
	}
}

To get the url parameters, simply use code like

if(window.location.hash) {
	var param = "parameter name";
	var checking = window.location.hash.split('param=')[1];
	if( checking == 'checked' ){	
		//do something here
		alert(param);
	}            				    
}

By Keenlio, May 21, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *


× 8 = twenty four

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>