How To Avoid Document.write In An External Script
Solution 1:
I will try to explain @freedomm-m's suggestion, hoping to be clear.
To re-assign document.write
, which returns a function, to an "empty function"... could do the trick to avoid the "normal" execution of document.write
.
By "empty function", I mean a totally valid function, but doing strictly nothing.
So after that re-assignment, every times the document.write
function will be called anywhere in the document, instead of executing the write
function found under the document
object's property, it will execute that "empty function" (read: Nothing).
Here is a demo of that principle applyed on the console.log
function, just to keep it simple and be obvious in this demo here.
console.log("I am executing...")
console.log("I am executing too...")
// Assing an empty functionconsole.log = function(){}
console.log("I am NOT executing!")
console.log("I feel useless now... :( ")
Now to "temporarly" avoid a function execution, you have to store it in another variable in order to "undo" the re-assigment...
console.log("I am executing...")
console.log("I am executing too...")
// Assign the function to a variablelet tempStorageOfTheDisabledFunction = console.log// Assing an empty functionconsole.log = function(){}
console.log("I am NOT executing!")
console.log("I feel useless... :( ")
// Restore the original functionconsole.log = tempStorageOfTheDisabledFunction
console.log("Yeah! I'm back in play!")
console.log("I feel better.")
So now, what fredomm-m suggested to try is:
<script>document.write = function(){}</script><scriptsrc="path-to-external-js"></script>
Post a Comment for "How To Avoid Document.write In An External Script"