본문 바로가기
WWWEB/Script

[js] 시크릿 모드 체크하기 예시

by 미니토이 2022. 12. 22.

 

크롬 브라우저는 쿠키, 세션, 기록, 양식 데이터, 비밀번호 및 임시 데이터를 저장하고,

시크릿 모드는 이러한 정보를 별도의 위치에 저장하고 시크릿 창이 닫히면 삭제하게 된다고 함.

 

사이트 정책에 따라 쿠키나 세션을 사용할 수 없는 경우 문제가 되는 경우가 있는데,

아래 스크립트를 이용해서 사용자가 시크릿모드를 사용하는지를 체크해볼 수 있음~

 

 

 

1. function 작성

/**
 * 시크릿모드 확인(Determine wheter the incognito mode of Google Chrome is available or not.)
 * 
 * @시크릿모드인 경우 반환되는 익명함수
 */
function isPrivateMode( callback ){
    let fileSys = window.RequestFileSystem || window.webkitRequestFileSystem;

    if ( !fileSys ){
        callback( false );
    } else {
        fileSys(window.TEMPORARY,
            100,
            callback.bind( undefined, false ),
            callback.bind( undefined, true )
        );
    }
}

 

 

 

2. 실행

isPrivateMode(function( t ){
    if( t ){
        console.log( "시크릿모드 O" );
    }else{
        console.log( "시크릿모드 X" );
    }
});

 

 

728x90
반응형

댓글