How do I load this asynchronously

Discussion in 'JavaScript' started by Matt Jo, Jul 1, 2011.

  1. #1
    Matt Jo, Jul 1, 2011 IP
  2. tolas

    tolas Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Haven't got a clue about why you want to do it like that, but you can always put a link in the <head> section by doing from javascript:

    function myFunc() {
    document.getElementsByTagName('HEAD')[0].innerHTML += '<script type="text/javascript" src="http://www.google-analytics.com/ga.js" onload="myFunc2();"></script>';
    }

    function myFunc2() {
    var pageTracker = _gat._getTracker("YOURGOOGLEID");
    pageTracker._initData();
    pageTracker._trackPageview();
    }

    Then you can call myFunc() from anywhere to load your ga.js at any time.
     
    tolas, Jul 9, 2011 IP