How to check if ajax.googleapis.com is blocked and use my jquery hosting?

I use http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js but some compatibility may block this site, so in this case I want to use my local version on jquery / JavaScripts / jquery.min.js. How can i do this?

+3
source share
1 answer
if(typeof(jQuery) === 'undefined'){             
    var scr =   document.createElement('script');
                scr.setAttribute('type', 'text/javascript');
                scr.setAttribute('src', 'http://yourdomain/jquery.min.js');

    document.getElementsByTagName('head')[0].appendChild(scr);
    setTimeout(function(){
        // $(document).ready(); here for instance
    }, 3000);
+1
source

Source: https://habr.com/ru/post/1743489/


All Articles