Is there a way to console.log()
every time a document.write()
occurs?
Something like this (which doesn't seem to work):
$(document).on('write', function() {
console.log('write occurred');
});
Is there a way to console.log()
every time a document.write()
occurs?
Something like this (which doesn't seem to work):
$(document).on('write', function() {
console.log('write occurred');
});
可能不是最好的方法,但你可以重新定义document.write
.
document.__write = document.write; // copy the original definition
// redefine
document.write = function(contents) {
console.log(contents); // log
document.__write(contents); // call the original
}
PS - 要监视 DOM 的更改,您应该使用更健壮的东西,例如Mutation 事件