SORU
18 Kasım 2008, Salı


Nasıl bir URL JavaScript kullanarak #sağlaması için bir kontrol EDEBİLİR MİSİN?

Karma olduğu zaman çalıştırmak istediğim bazı jQuery JavaScript kodu var (#) çapa bir URL bağlantısı. Nasıl bu karakter için JavaScript kullanarak kontrol EDEBİLİR MİSİN? Basit bir bu gibi: URL algılamak verecek-tüm yakalamak testi yapmak istiyorum

  • example.com/page.html#anchor
  • example.com/page.html#anotheranchor

Çizgisinde temelde bir şey

if (thereIsAHashInTheUrl) {        
    do this;
} else {
    do this;
}

Eğer herkes doğru yönde bana gelin olabilir, bu çok mutluluk duyacağız.

CEVAP
18 Kasım 2008, Salı


Basit:

if(window.location.hash) {
  // Fragment exists
} else {
  // Fragment doesn't exist
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Android Developers

    Android Deve

    9 Kasım 2007
  • Flash CS6 Video Tutorials for Beginners (Actionscript 3 Gaming)

    Flash CS6 Vi

    14 EYLÜL 2012
  • ODN

    ODN

    26 Kasım 2006