Created
March 19, 2016 05:44
-
-
Save aNd1coder/29c76388158517b29cbb to your computer and use it in GitHub Desktop.
用全局变量接收创建的Image对象,防止临时变量被回收而导致统计数据丢失
This file contains hidden or 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
// http://oldj.net/article/one-thing-to-notice-about-new-image/ | |
var img = new Image(); | |
var rnd_id = "_img_" + Math.random(); | |
window[rnd_id] = img; // 全局变量引用 | |
img.onload = img.onerror = function () { | |
window[rnd_id] = null; // 删除全局变量引用 | |
} | |
img.src = "http://log.mysite.com/1.gif?a=1&b=2&c=xxx"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment