f-angi
3/25/2016 - 4:33 PM

Downloads and executes a script from a site on a different domain. Scenario: you need to download a script using a <script src="..."/>, but

Downloads and executes a script from a site on a different domain. Scenario: you need to download a script using a

$.ajax({
    type: 'GET',
    url:  "www.another-site.com/script.js",
    dataType : 'jsonp',
    crossDomain:true,
    success: function(data, status) {
        console.log(data);
    }
});

/*
In this way you can access at the data returned from another-site.com/script.js.
It may be the case that the script (returned as 'data') executes a 
document.write(). As this is not allowed, you can override the write function, 
e.g. before the ajax call you can write...
*/
document.write = function(data) { console.log(data); }