SORU
29 Ocak 2010, Cuma


Js URL çapa değiştirme olayı işlemek

Nasıl bu URL herhangi bir değişiklik çapa üzerinde yürütülen JavaScript geri arama kodu yazabilirim?

http://example.com#b http://example.com#a örneğin

CEVAP
29 Ocak 2010, Cuma


Google Özel Arama motoru bir çekim için onay karma karşı bir önceki değeri, buna rağmen çocuk iframe üzerinde ayrı bir etki alanı güncellemeleri ebeveynin konumu karma içeren boyutu iframe belgenin vücut. Zamanlayıcı değişim yakalar, üst kaydırma çubukları görüntülenmez. böylece vücudun bu maç için iframe yeniden boyutlandırma.

Aşağıdaki gibi aynı elde:

var storedHash = window.location.hash;
window.setInterval(function () {
    if (window.location.hash != storedHash) {
        storedHash = window.location.hash;
        hashChanged(storedHash);
    }
}, 100); // Google uses 100ms intervals I think, might be lower

Google, Opera 10.60, Firefox 3.6 5 Internet Explorer 8 Safari 5, Chrometümhashchange olay destek:

if ("onhashchange" in window) // does the browser support the hashchange event?
    window.onhashchange = function () {
        hashChanged(window.location.hash);
    }

ve bir araya getirmek:

if ("onhashchange" in window) { // event supported?
    window.onhashchange = function () {
        hashChanged(window.location.hash);
    }
}
else { // event not supported:
    var storedHash = window.location.hash;
    window.setInterval(function () {
        if (window.location.hash != storedHash) {
            storedHash = window.location.hash;
            hashChanged(storedHash);
        }
    }, 100);
}

ayrıca jQuery hashchange olay kontrol edin ve gerekirse kendi sağlamak http://benalman.com/projects/jquery-hashchange-plugin/ bir eklenti var.

EDİT: Güncellenmiş destek (tekrar) tarayıcı.

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Kenneth Håkonsen

    Kenneth Håk

    13 Mart 2011
  • SuperPrincessjo

    SuperPrinces

    1 EKİM 2010
  • Wronchi Animation

    Wronchi Anim

    9 Mayıs 2011