0

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');
});
4

1 回答 1

3

可能不是最好的方法,但你可以重新定义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 事件

于 2013-09-15T04:36:48.050 回答