Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window location 1

Status
Not open for further replies.

peacecodotnet

Programmer
May 17, 2004
123
0
0
US
I want to perform different actions depending on what a user types after a # symbol to a web page. For example, if they visited page.html#hello, a screen would say hello to them. But if they visited page.html#goodbye, it would say goodbye. I'm not asking how to make the content appear, but rather how to detect what they have put after the # symbol.

Thanks!

Peace out,
Peace Co.
 

Here is a function you can easily modify to do just what you ask:

Code:
<script type="text/javascript">
<!--
function checkHref() {
	var myhref = location.href.split('#');
	if (myhref.length > 1)
	{
		switch (myhref[1])
		{
			case 'hello':
			{
				alert('Hello!');
				break;
			}
			case 'goodbye':
			{
				alert('Goodbye!');
				break;
			}
		}
	}
}
//-->
</script>

Hope that helps!
Jeff

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top