Home >Web Front-end >JS Tutorial >JavaScript page encoding and browser type judgment code_javascript skills

JavaScript page encoding and browser type judgment code_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:25:391103browse

To get the encoding of the page, if you use IE browser, you can use document.charset. If you use Firefox, you need to use
document.characterSet.

Copy code The code is as follows:

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

//Get The type of browser is IE or Firefox
Copy code The code is as follows:

function getBrowser() {
var oType = "";
if(navigator.userAgent.indexOf("MSIE")!=-1){
oType="IE";
}else if(navigator.userAgent .indexOf("Firefox")!=-1){
oType="FIREFOX";
}
return oType;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn