Yalnızca URL'de bir karma (#
) bağlantı olduğunda çalıştırmak istediğim bazı jQuery/JavaScript kodlarım var. JavaScript kullanarak bu karakteri nasıl kontrol edebilirsiniz? Bu gibi URL'leri tespit edebilecek basit bir teste ihtiyacım var:
example.com/page.html#anchor
example.com/page.html#anotheranchor
Temel olarak şöyle bir şey:
if (thereIsAHashInTheUrl) {
do this;
} else {
do this;
}
Beni doğru yöne yönlendirebilecek biri varsa çok memnun olurum.
Şunları koyun:
<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>