Get Value from Url
i have a following url
http://example.aspx#gbar
where #gbar is a Anchor. if this anchor is available i have to do to hide some div and show some div . How will i check if the url has this anchor ,because it is not a query string we cna't use request.querystring.get() .Any ideas 开发者_开发技巧??
Javascript location hash property sets or returns the value from the hash sign "#" in the current URL of the browser window. Javascript location hash actually returns the bookmark name form the current URL. Bookmark hash "#" sign provides the functionality to target the named anchor HTML tag within the same other web pages. When you click on any link text that targets the bookmarked location of any webpage it adds the "#" symbol and bookmark name to the end of the URL. You can place the location.hash or window.location.hash code inside the target page to retrieve the current bookmark name from the URL. You can call the function at page load or click event of the button.
<html>
<head>
<title>Javascript Window Location Hash</title>
<script type="text/javascript" language="javascript">
function getLocationHash()
{
alert(window.location.hash);
}
function setLocationHash()
{
window.location.hash = "#top";
}
</script>
</head>
<body>
<p>
Click here to <a name="top" href="#bottom" style="color: blue"><b>go to Bottom >></b></a> <br />
Sample Text Sample Text Sample Text Sample Text Sample Text Sample Text <br />
</p>
<p>
Click here to <a name="bottom" href="#top" style="color: blue"><b>go to Top</b></a>
</p>
<input type="button" onclick="getLocationHash();" value="get Location Hash" />
<input type="button" onclick="setLocationHash();" value="set Location #Top" />
</body>
</html>
In JavaScript
location.hash
Edit: Changed from "document.location" on advice below
location.hash
精彩评论