Javascript Detect All Images (Including Asynchronous)
Is there a way in javascript to detect all images in a document, including those that may be loaded asynchronously (and maybe after the DOM is ready)?
I'm looking to create a function that can detect if Google Analytics has been loaded by searching through the DOM looking for "__utm.gif". document.images doesn't seem to开发者_开发问答 hold this image as it's loaded asynchronously and not displayed.
Is there any reason you don't want to implement GA detection by checking for the HTTP request to which this gif (i.e., __utm.gif) is appended?
It's this request that's responsible for sending all of the data GA collects to the GA servers, and of course the request is made every time the page is requested or an event is fired on that page.
Again, this request has a very distinct signature--it always begins like this:
http://www.google-analytics.com/__utm.gif?utmwv=4&utmn
Here's a complete example from the GA Site.
If you're looking to detect GA, you can simply test for window._gat and window._gaq.
精彩评论