在页面中,我拥有由外部脚本生成的第三方广告内容。加载此内容需要一些时间。我想从广告内容中删除一个换行符-为此,必须等到外部脚本加载完毕并且该脚本中调用的所有功能都停止运行之后,再进行操作。我正在修改以下想法,但我想它只等到加载外部脚本时才开始:
$.getScript( "http://www.external_site.com/widget.js").done( function(data, textStatus, jqxhr) {
$('.result').find('br').remove();
});
等待外部脚本执行其所有DOM操作之后再调用.remove()函数的最佳方法是什么?
一种方法似乎是侦听从其中运行JavaScript的新创建和插入的元素触发的onreadystatechange
和load
事件<script>
。
这在链接的(简单的)演示中有效,但是我不能证明其在大型项目中的可靠性:
// listening for the onreadystatechange and/or load
// events fired from the newly-added "script" elements:
$('script').on('onreadystatechange load', function (e) {
// performs the following simple/contrived functionality:
$('body').find('br').remove();
});
参考文献:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句