Go to My Blog
Go to Lin's Blog

JS在当前页面插入<script>标签,并执行

将<script>标签绑定到<html>上, html可换成body,header等其他存在的标签。

var htmm =document.getElementsByTagName("html")[0];
var scri = document.createElement("script");
scri.async="async"
scri.src="http://www.xxx.com/dummy.js"
scri.onload=function(){console.log("script onloaded");}
htmm.appendChild(scri);

Result:
  <script async src=​"http:​/​/www.xxx.com/​dummy.js">​</script>​
  dummy.js dummy.js:1
  script onloaded

 

posted @ 2014-10-24 09:35  一ke小小草  阅读(2322)  评论(0编辑  收藏  举报