index.php
<html>
<head>
<title>My Title</title>
<script type="text/javascript">
function getLink(data) {
document.getElementById("box").innerHTML="This is "+data;
}
</script>
</head>
<body>
<a href="#home" onClick="getLink('Home')">Home</a><br />
<a href="#profile" onClick="getLink('Profile')">Profile</a><br />
<a href="#message" onClick="getLink('Message')">Message</a><br />
<a href="#setting" onClick="getLink('Setting')">Setting</a><br />
<hr />
<div id="box"></div>
</body>
</html>
Output
Home
Profile
Message
Setting
This is Home
As the code says my Div
contents updated when i click any of the link
but the problem is that when user goes back
by clicking Back Button of Browser
the content of my Div
donot changes.
I want that either user Goes Back
, Goes Forward
or he directly puts the path in the address bar
www.*****/index.php#profile
the content of my Div
should be change.
Note
I used document.location.hash
to get the value of hash
like this :
<head>
<script>
var hashValue=document.location.hash;
alert(hashValue);
</script>
</head>
but it works only when user goes back
and then refresh the page
Plz help me how can i achieve this :(