码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2014-10-24 10:29:50      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   sp   div   on   

将<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

 

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

标签:style   blog   http   color   io   ar   sp   div   on   

原文地址:http://www.cnblogs.com/zzSoftware/p/4047473.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!