Created
March 21, 2012 21:21
-
-
Save dialtone/2152947 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var _onload = function(){ | |
if (document.readyState && !/loaded|complete/.test(document.readyState)){setTimeout(_onload, 10);return} | |
if (!window.__adroll_loaded){__adroll_loaded=true;setTimeout(_onload, 50);return} | |
var scr = document.createElement("script"); | |
var host = (("https:" == document.location.protocol) ? "https://s.adroll.com" : "http://a.adroll.com"); | |
scr.setAttribute('async', 'true'); | |
scr.type = "text/javascript"; | |
scr.src = host + "/j/roundtrip.js"; | |
((document.getElementsByTagName('head') || [null])[0] || | |
document.getElementsByTagName('script')[0].parentNode).appendChild(scr);}; | |
if (window.addEventListener) {window.addEventListener('load', _onload, false);} | |
else {window.attachEvent('onload', _onload)}}()); |
Line 3 is for WebKit, it happens to work also on IE. I don't need to know when the script is loaded, it's more when the page has finished loading so I can do my stuff from the script without having the user think that the page hasn't loaded yet.
I don't think it matters but the IIFE (like yours) are written like (function(){})(); and not (function(){}());
HTH
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't need line 3. For IE you can listen to script.onreadystatechange (and the subject should be the script, not the document).
Something along these lines (we use it for dinamically loading jQuery):