1

I have a page with a URL that includes a hash value (www.mysite.com/#123).

What I want to do is use that value to determine what is displayed on the page - much like using a querystring.

I am using the hash value because the content on the page can be changed client side (I am avoiding page reloads where possible) - if the user then links to another page and uses the back button to return, I need to use the hash value to display the page as it was when they left it.

So I'm looking for an if statement that will look something like this:

if hashvalue = 123 then
    Do this
else
    do that
End if

Any ideas?

Taz
  • 3,718
  • 2
  • 37
  • 59
Tom
  • 12,776
  • 48
  • 145
  • 240

1 Answers1

1

You have to use JavaScript window.location.hash attribute.

For instance,

<script type="text/javascript">
        window.onhashchange = function () {
            var hash = window.location.hash;
            switch (hash) {
                case "#120": alert("One"); break;
                case "#121": alert("Two"); break;
            }
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
      <a href="#120">One</a>
      <a href="#121">Two</a>    
    </form>
...
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186