繁体   English   中英

替换外部脚本的document.write

[英]Replacing document.write of external script

有什么方法可以替换我无法编辑的外部脚本的document.write吗?

<div class="mydiv">
        <script type="text/javascript" src="https://www.formstack.com/forms/js.php?3349003-8L4WS0Z6Xi"></script>
</div>

我尝试了下面的代码来替换它,但它只是搞砸了所有的事情

document.write=function(s){
    var scripts = document.getElementsByTagName('script');
    var lastScript = scripts[scripts.length-1];
    lastScript.insertAdjacentHTML("beforebegin", s);
}```

不知道为什么要覆盖它,也许是为了提高 append 的性能?

document.write = function(s) {
    document.body.append(s)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM