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

  • CasinoRoyaleMovie's channel

    CasinoRoyale

    1 AĞUSTOS 2006
  • ghosti66

    ghosti66

    27 AĞUSTOS 2006
  • Samvith V Rao

    Samvith V Ra

    20 EKİM 2006