Skip to content

Instantly share code, notes, and snippets.

@RadLikeWhoa
Last active December 20, 2015 13:29
Show Gist options
  • Select an option

  • Save RadLikeWhoa/6139454 to your computer and use it in GitHub Desktop.

Select an option

Save RadLikeWhoa/6139454 to your computer and use it in GitHub Desktop.
(function () {
var _id = 0
window.jsonp = function (url, callback) {
var id = 'jsonp_cb_' + _id,
existing = document.scripts[0],
script = document.createElement('script')
window[id] = function (data) {
script.parentNode.removeChild(script)
callback(data)
delete window[id]
}
script.src = url + (~url.indexOf('?') ? '&' : '?') + 'callback=' + id
existing.parentNode.insertBefore(script, existing)
_id += 1
}
}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment