數據庫用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>
亂碼從此不再出現!