javascript - 覆盖 document.write
问题描述
我正在尝试覆盖 document.write,因此我将能够获取原始 html 解析它对代码进行一些操作并返回调用。我的整个过程是异步的,所以不用说当页面完成加载 document.write 时调用 document.write 将擦除整个文档,所以我不记得 document.write。我已经搜索并发现了很多关于此的讨论,但几乎每个讨论都非常古老,所以我找不到任何好的答案。我现在的代码非常基本:
const prevDocWrite = document.write;
document.write = function(str,patched) {
if(patched){
prevDocWrite.call(this, str);
}else{
Dom_Parser(str, context).then(newStr => {
prevDocWrite.call(this, newStr);
})};
};
我添加了“修补”部分,因为我也在我的代码上调用 document.write,所以我像 document.write("str",true) 一样调用它,它会立即调用原始 document.write。
我非常感谢任何帮助或想法如何实现这一点(其他项目供参考会很棒)
顺便说一句,我看到了很多使用 innerHtml 的实现,但这搞砸了<script>
标签:(
多谢
解决方案
推荐阅读
- java - java - 如何在Java中使用带有@JsonFormat的'dd-MMM-yyyy'来解析日期?
- javascript - Jeditable 不适用于动态创建的表行
- c# - 在这个地方向 DI 容器添加服务不起作用
- python - 导入简单的 C 扩展模块时 Python 报错
- apache - 如何使用 DirectAdmin 在 Debian 10 上启用 Brotli?
- java - 在 HTTP 标头中使用 SOAPAction 在 JAVA 中使用 SOAP 服务
- r - 使用 R 将绘图图像嵌入到 powerpoint 中
- elasticsearch - elasticsearch 嵌套查询仅返回最后 3 个结果
- python - 传递函数的 Python 状态空间计算
- php - Laravel 在主机上注册不起作用