Question

Cette fonction désactive l'action par défaut pour un lien et modifie l'URL à l'aide de la fonction pushState.Je dois pouvoir détecter si un navigateur ne prend pas en charge cette fonction, afin de pouvoir arrêter la fonction preventDefault ().

$("a").click(function(event) {      

            var url = "";
            var url = $(this).attr('href'); 

        // Disable Default Action and Change the URL -  
        event.preventDefault();     
        window.history.pushState("somedata", "Title", url);

        //Call Function to change the content - 
        loadContent(url);
    });

Toutes les recommandations sont grandement appréciées

Était-ce utile?

La solution

Utilisez la détection des fonctionnalités:

if (history.pushState) {
  // supported.
}

Exemple:

$("a").click(function(event) {      
    var url = "";
    var url = $(this).attr('href'); 

    if (history.pushState) {
        window.history.pushState("somedata", "Title", url);
        event.preventDefault();
    }

    //Call Function to change the content - 
    loadContent(url);
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top