偵測當前頁面編碼


function getCharset(){
    var charSet = "";
    var oType = getBrowser();
    switch(oType){
        case "IE":
            charSet = document.charset;
            break;
        case "FIREFOX":
            charSet = document.characterSet;
            break;
        default:
            break;
    }
    return charSet;
}

實測結果:
Chrome: document.charset  和  document.characterSet  皆可   (回傳UTF-8)
Firefox: document.characterSet 可  document.charset  不可    (回傳UTF-8)
IE: document.charset 可   document.characterSet  不可    (回傳utf-8)
Safari: document.charset  和  document.characterSet  皆可   (回傳UTF-8)

留言

熱門文章