日期:2014-05-16  浏览次数:20318 次

js 文件加载时候页面缓存的问题
意思:就是给js文件加上时间戳或者随机数
	<script type="text/javascript">
		var t= Math.random();
		var js_path = "include/js/";
		function js_include(script){ 
			var script = document.createElement('script'); 
			script.src = js_path + script; 
			script.language = 'javascript';
			script.type = 'text/javascript'; 
			var head = document.getElementsByTagName('head').item(0); 
			head.appendChild(script);
		} 

		(function(){
		  	var loadjs = function(){
		  		var s = document.createElement('script');
		  		s.src = "http://union.500wan.com/ushare/add.js";
		  		s.type = "text/javascript";
		  		s.charset="gbk";
		  	    var h = document.getElementsByTagName('head')[0];
		  	    h.appendChild(s);
		  	}
		  	if(/msie/i.test(navigator.userAgent)){
		  		window.attachEvent('onload',function(){
		  			loadjs();
		  		});
		  	} else {
		  		window.addEventListener('load',function(){
				  
		  			loadjs();
		  			
		  			
		  		},false);
		  	}
		})()
		
		js_include("prototype.js?t=" + t);
	</script>