// calls `cb` with the data from `url`, which either ends with a "=" (for the callback), // or handles the standard "&callback=" query parameter, as well-organized JSON APIs do. function JSONP(url, cb) { var nth = JSONP.nth = (JSONP.nth || 0) + 1 , name = 'cb' + nth.toString(36) , tail = /=$/.test(url) ? '' : (/\?/.test(url) ? '&' : '?') + 'callback=' , head = document.getElementsByTagName('head')[0] , load = document.createElement('script'); JSONP[name] = function(json) { delete JSONP[name]; head.removeChild(load); cb(json); }; load.src = url + tail + 'JSONP.'+ name; head.appendChild(load); }