Run dynamically inserted javascript in the DOM loaded via AJAX (attempt to ajaxify the site with history.js)

I have a web application that essentially has headers, lower and upper body. I am working on ajaxification of a website using the history.js library and HTML5 pushstate, but one of the problems I ran into is running inline javascript to start when javascript is inserted into the DOM.

Almost all of my javascript is wrapped in jQuery (function () {...}) (the downloadable document is ready to download)

Does anyone know a good strategy to deal with this? Thank!

+5
source share
2 answers

, "" - HTML, . HTML JavaScript script, . ? script ?

, , : JavaScript?

:

, JavaScript , - , , JavaScript , , , .

, , , jQuery, .getScript() .ajax(). , , http://www.electrictoolbox.com/jquery-dynamically-load-javascript-file/.

, , , html-, , html script script, . , script jQuery , .

(function () {

    if (typeof(jQuery) == "undefined") {
        var headID = document.getElementsByTagName("head")[0];         
        var newScript = document.createElement('script');
        newScript.type = 'text/javascript';
        newScript.id = 'myjQuery';
        newScript.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js';
        headID.appendChild(newScript);
    }

    window.addEventListener('load', function (e)  {

        //make jQuery calls here.

    }, false);

})();
+7

. , , :

dom, , "onclick" div, , x

-1

All Articles