去除静态html的缓存--动态引入js文件
2017-03-09 本文已影响208人
hey_沙子
动态引入js文件以及在js文件后边添加动态参数
<script src="http://wechat.yiwang.com/appwxshare/js/share_test.js" type="text/javascript" ></script>
<html>
<meta charset="utf-8" />
<body>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script>
window.onload=function(){
var script=document.createElement("script");
script.setAttribute("type", "text/javascript");
var num=Math.random();
var _url="http://wechat.yiwang.com/appwxshare/js/share_test.js?v="+num;
script.setAttribute("src", _url);
var heads = document.getElementsByTagName("head");
if(heads.length) {
heads[0].appendChild(script);
}
}
</script>
</body>
</html>