【发布时间】:2013-01-06 10:54:04
【问题描述】:
我正在开发一个需要我拦截 document.write 函数的 Chrome 扩展程序(注意:我正在使用内容脚本)。我在这里使用的方法:http://sitr.us/2012/09/04/monkey-patching-document-write.html 但它不能正常工作。这就是我现在拥有的:
(function() {
var originalWrite = document.write;
alert("checkpoint 1");
document.write = function() {
alert("checkpoint 2");
//secret stuff here
return Function.prototype.apply.call(
originalWrite, document, arguments);
}
})();
但是,当我在网页上调用 document.write 时,我的钩子中的“检查点 2”警报永远不会被调用。我究竟做错了什么?
【问题讨论】:
-
不确定扩展的工作流程...但是您尝试过
return originalWrite.apply(this, arguments);吗?