Skip to content Skip to sidebar Skip to footer

Can't Load Script As Plain Text With Ajax

I have a javascript file in a server I can't modify. Here is a sample of the script I have to download: var tags = ''; tags += 'document.write.

Before you run the script, do:

document.write = function(msg) {
    handleTagStringInApp(msg);
    deletedocument.write; // revert to original document.write when done
};
// now load execute the script...

where handleTagStringInApp is a function you write that processes the tag string somehow. This is basicallyJSONP, but you can't adjust the callback name to be something unobtrusive or helpful and must instead use the callback name document.write.

Note that this will be really bad if anything else in your app actually needs to use document.write. (You might get around this in your own code by keeping a reference to the real document.write, e.g., using var realDocWrite = document.write; on page load and calling it with realDocWrite.call(document, "whatever").)

Post a Comment for "Can't Load Script As Plain Text With Ajax"