hello, I use the history.pushtate function to asynchronously change what comes after the domain.

but there is a problem, some browsers that do not support history do not just do not allow using this feature, but the js code does not work completely and the site becomes unusable. How can you solve this situation? whether to do some kind of check before launching a function that will determine whether the browser supports it or not, preventing launch

    2 answers 2

    Check it out is pretty simple:

    function isHistoryApi() { return !!(window.history && history.pushState); } 

    Another question is that since you use history, then many other features of html5 are possible. If so, this may be the reason why nothing works in certain browsers.

    To solve this problem, Modernizr was created. Following the link you can find a list of features that can be checked with Modernizr.

      Check the existence of a function in the forehead

       if(window.history && history.pushState) { // .. Здесь ваш код } 

      Or catch errors

       try { // .. Ваш код с history.pushState } catch(e) {}