異步加載js不能使用document.write

document已經加載解析完畢,文檔流已經關閉了app

因此你異步加載的js不能夠再往document裏寫東西了,好比使用document.writedom

不過你能夠用dom方法添加異步

.appendChild()google

.insertBefore()spa

.innerHTMLcode

解決方法:你能夠把script加載放在body標籤結束以前blog

例如:ip

<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
相關文章
相關標籤/搜索