数据库用UTF-8,现有系统用gb2312,
用<script>echo_script(url);</script>
复制代码 代码如下:
<script>
function echo_script(url){
var USERAGENT = navigator.userAgent.toLowerCase();
var bname = '';
var b = ['ie','msie','firefox','chrome','opera','safari','maxthon','mozilla','webkit'];
for(i in b){
if(USERAGENT.indexOf(b[i]) > -1){
bname = b[i];
break;
}
}
if(!bname)bname='other';
var ie8 = USERAGENT.indexOf('msie 8') > -1 ? 'ie8' : false;
var ie7 = USERAGENT.indexOf('msie 7') > -1 ? 'ie7' : false;
if(bname == 'firefox' || ie8 )
{
var enc = "no";
}
if(ie8){
bname = 'ie8';
}else if(ie7){
bname = 'ie7';
}
var tmp_ie8 = ie8 ? 'ie8' : 'no_ie8';
document.write("<script src='"+url+"&encode="+enc+"&browser="+tmp_ie8+"&browserv="+bname+"'></script>");
}
</script>
哎,这种方法,导致在不同的浏览器下乱码不断,害苦我了。
有更简单的办法
<script type="text/javascript" charset="utf-8" src="xx.com/xx.php"></script>
乱码从此不再出现!