页面加载后在html正文中注入外部javascript文件 [英] Inject external javascript file in html body after page load
本文介绍了页面加载后在html正文中注入外部javascript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在加载页面后加载外部JavaScript。实际上,javascript包含广告的来源,并且其制作页面加载速度很慢。我只想延迟加载和执行广告以确保快速加载页面。
I want to load an external javascript after page is loaded. Actually the javascript contains source for an ad and its making page load slow. All I want is to delay loading & execution of ads to make sure fast page load.
谢谢,
Bilal
thanks, Bilal
推荐答案
您可以在主体块的最后一个标签处使用此脚本:
You may just use this script at the last tag of your body block:
<script type="text/javascript">
var script = document.createElement('script');
script.setAttribute('src', 'http://yourdomian.com/your_script.js');
script.setAttribute('type', 'text/javascript');
document.getElementsByTagName('head')[0].appendChild(script);
</script>
这篇关于页面加载后在html正文中注入外部javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文