function execJSONP(url, cb) { //url (without "callback=" parameter!) and callback function var script = document.createElement('script'); script.async = true; var callb = 'exec'+Math.floor((Math.random()*65535)+1); window[callb] = function(data) { var scr = document.getElementById(callb); scr.parentNode.removeChild(scr); cb(data); window[callb] = null; delete window[callb]; } var sepchar = (url.indexOf('?') > -1)?'&':'?'; script.src = url+sepchar+'callback='+callb; script.id = callb; document.getElementsByTagName('head')[0].appendChild(script); }