JavaScript overwrite native methods overwrite native method

Abstract: JavaScript overwrite native methods overwrite native method


If you think the eval is evil, it is prohibited by overwriting eval ...

Of course, this always goes wrong in a formal environment, even if no one is using eval, and really someone, let someone else's program is not broken play it XD

To inform the user program execution results, or other information, may use alert, if you feel alert ugly, very out of the way, very friendly, you can also override the alert

But the alert can not simulate some properties, such as pause script execution, or to alert a sequence executed in practice a little bit of trouble, as well as to continue blocking mouse click on the page and the like ... so this idea is not only done override play XD; the rest can win part of the original API I only think of UI adjustment, so that each browser interface alert to be better than the same ... but this part of jQuery UI to do better to get more ... jQuery UI directly with XD

Then is the origin of the article ... (yes, in front of all extended XD), just want to override document.write, record the contents of each write, so I wrote this

But I met a middle can not understand the error

(function(doc) {
    doc.write(123);
    var _write = doc.write;
    _write.apply(doc, [123]);
    //_write(123); //CHROME: Illegal invocation,为什么?如果是安全性考量,为什么透过 apply又可以执行?
})(document);

Can attack through this way override the original method was originally in cyber attacks inside to see the article, script file other injection site after ... a defensive way is by creating a clean, safe environment iframe produce, then: Note there's a native method, a large circle around, and focus should be on the defensive to avoid being injected ah ~!

Original: Big Box  JavaScript overwrite native methods overwrite native method


Guess you like

Origin www.cnblogs.com/chinatrump/p/11491079.html