Mám nejaký kód jQuery/JavaScript, ktorý chcem spustiť len vtedy, keď je v adrese URL kotva odkazu s hashom (#
). Ako sa dá tento znak kontrolovať pomocou JavaScriptu? Potrebujem jednoduchý záchytný test, ktorý by odhalil takéto adresy URL:
example.com/page.html#anchor
example.com/page.html#anotheranchor
V podstate niečo v tomto zmysle:
if (thereIsAHashInTheUrl) {
do this;
} else {
do this;
}
Ak by ma niekto mohol nasmerovať správnym smerom, veľmi by som to ocenil.
Uveďte tieto údaje:
<script type="text/javascript">
if (location.href.indexOf("#") != -1) {
// Your code in here accessing the string like this
// location.href.substr(location.href.indexOf("#"))
}
</script>