Last active
August 28, 2017 06:08
-
-
Save Dafrok/443187420034d4564fcb41ece43450e1 to your computer and use it in GitHub Desktop.
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
| (function (global, factory) { | |
| typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | |
| typeof define === 'function' && define.amd ? define(factory) : | |
| (global.getJSONP = factory()); | |
| }(this, function () { 'use strict'; | |
| var global = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this; | |
| return function getJSONP (url, callback) { | |
| var dt = new Date(); | |
| var callbackName = 'JSONP_' + Date.parse(dt) + dt.getMilliseconds(); | |
| global[callbackName] = callback; | |
| var ref = global.document.getElementsByTagName('script')[0]; | |
| var script = global.document.createElement('script'); | |
| script.src = url + (url.indexOf('?') + 1 ? '&' : '?') + 'callback=' + callbackName; | |
| ref.parentNode.insertBefore(script, ref); | |
| script.onload = function () { | |
| delete(global[callbackName]); | |
| this.remove(); | |
| }; | |
| } | |
| })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment