[英]Replacing document.write of external script
Is there any way to replace document.write
of an external script that I can't edit?有什么方法可以替换我无法编辑的外部脚本的
document.write
吗?
<div class="mydiv">
<script type="text/javascript" src="https://www.formstack.com/forms/js.php?3349003-8L4WS0Z6Xi"></script>
</div>
I tried the below code to replace it but it just messed up all the things我尝试了下面的代码来替换它,但它只是搞砸了所有的事情
document.write=function(s){
var scripts = document.getElementsByTagName('script');
var lastScript = scripts[scripts.length-1];
lastScript.insertAdjacentHTML("beforebegin", s);
}```
Not sure why you want to overwrite it, maybe to improve performance with append?不知道为什么要覆盖它,也许是为了提高 append 的性能?
document.write = function(s) {
document.body.append(s)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.