I work with an advertising company, where we tag certain pages to track activity. A client of mine wants to fire off a javascript tag to track activity AFTER the page has finished loading entirely (to prevent the page content from loading slowly due to slow tag load times).
An example tag that should load AFTER the page has fully loaded is:
<script>document.write('<s'+'cript language="JavaScript" src="http://jact.atdmt.com/jaction/JavaScriptTest"></s'+'cript>')</script>
I was looking at some stackoverflow threads and I came across the below implementation which I think will work:
window.onload = function(){
<script language="JavaScript" src="http://jact.atdmt.com/jaction/JavaScriptTest"></script>
};
I tested this on my own webpage and I did get the tag to fire off, but I'm wondering if there are any alternate or more robust methods, ideally using jquery of some kind.
Below is a sample implementation that the client tried, but it seems to break their page:
<script>
jQuery(window).load(function () {$('<script language="JavaScript" src="http://jact.atdmt.com/jaction/JavaScriptTest"></script>').insertAfter('#div_name');});
</script>
I haven't done JQuery in a while and was hoping I could get some input from other members here. Is there any other way I can call the above script after page load using JQuery?
Thanks,
question from:
https://stackoverflow.com/questions/19737031/loading-scripts-after-page-load 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…