JS는 액세스 장치가 모바일 쪽에서 왔는지 웹 쪽에서 왔는지 판단합니다
2345 단어 JS 페이지에 액세스하는 장치 가져오기
<script type="text/javascript">
(function(){
if(document.location.href.indexOf('a.com.cn')>-1){
setCookie("web_version","web",3600*3,'.com.cn');
}
var ua = navigator.userAgent.toLowerCase();
function setCookie(name,value,expires,path,domain,secure){
var cookieText = encodeURIComponent(name) + "=" + encodeURIComponent(value);
if(expires instanceof Date){
cookieText += ";expires=" + expires.toGMTString();
}
if(path){
cookieText += ";path=" + path;
}
if(domain){
cookieText += ";domain=" + domain;
}
if(secure){
cookieText += ";secure";
}
document.cookie = cookieText;
}
function unset(name,path,domain,secure){
setCookie(name,"",new Date(0),path,domain,secure);
}
function getCookie(name){
var cookieName = encodeURIComponent(name) + "=",
cookieStart = document.cookie.indexOf(cookieName),
cookieValue = null;
if(cookieStart>-1){
var cookieEnd = document.cookie.indexOf(";",cookieStart);
if(cookieEnd == -1){
cookieEnd = document.cookie.length;
}
cookieValue = decodeURIComponent(document.cookie.substring(cookieStart + cookieName.length,cookieEnd));
}
return cookieValue;
}
var uaLower = ua.toLocaleLowerCase();
if( (uaLower.indexOf('android') > -1) || ( uaLower.indexOf('iphone') > -1) || ( uaLower.indexOf('ipad') > -1) ||( uaLower.indexOf('moblie') > -1) ){
if(false){
}else{
var jump = getCookie("web_version");
if(jump == null){
window.location = 'http://a.com.cn';
setCookie("web_version","web",3600*3,'.com.cn');
}else{
if(jump == "wap"){
window.location = 'http://a.com.cn';
}else if(jump == "web"){
// window.location = 'http://a.com.cn';//
}
}
}
}
})();
</script>