Cookieチェック

<cfprocessingdirective pageencoding="UTF-8">
<cfprocessingdirective suppresswhitespace="yes">

<!-- スクリプト -->
<script type="text/javascript">

/**********
	ブラウザ判別用コード ここから
	
	以下のページより
	
	https://w3g.jp/blog//js_browser_sniffing
**********/
var _ua = (function(){
 return {
  ltIE6:typeof window.addEventListener == "undefined" && typeof document.documentElement.style.maxHeight == "undefined",
  ltIE7:typeof window.addEventListener == "undefined" && typeof document.querySelectorAll == "undefined",
  ltIE8:typeof window.addEventListener == "undefined" && typeof document.getElementsByClassName == "undefined",
  ltIE9:document.uniqueID && typeof window.matchMedia == "undefined",
  gtIE10:document.uniqueID && window.matchMedia,
  Trident:document.uniqueID,
  Gecko:'MozAppearance' in document.documentElement.style,
  Presto:window.opera,
  Blink:window.chrome,
  Webkit:typeof window.chrome == "undefined" && 'WebkitAppearance' in document.documentElement.style,
  Touch:typeof document.ontouchstart != "undefined",
  Mobile:(typeof window.orientation != "undefined") || (navigator.userAgent.indexOf("Windows Phone") != -1),
  ltAd4_4:typeof window.orientation != "undefined" && typeof(EventSource) == "undefined",
  Pointer:window.navigator.pointerEnabled,
  MSPoniter:window.navigator.msPointerEnabled
 }
})();
/**********
	ブラウザ判別用コード ここまで
**********/

 
$(function(){	


//Cookieの値を取得 getCookie(クッキー名); 
function getCookie(c_name){
	var st="";
	var ed="";
	if(document.cookie.length>0){
		// クッキーの値を取り出す
		st=document.cookie.indexOf(c_name + "=");
		if(st!=-1){ 
			st=st+c_name.length+1;
			ed=document.cookie.indexOf(";",st);
			if(ed==-1) ed=document.cookie.length;
			// 値をデコードして返す
			return unescape(document.cookie.substring(st,ed));
		} 
	}
	return "";
}

//Cookie保存 setCookie(クッキー名, クッキーの値, クッキーの有効日數); 
function setCookie(c_name,value,expiredays){
	// pathの指定
	var path = location.pathname;
	// pathをフォルダ毎に指定する場合のIE対策
	var paths = new Array();
	paths = path.split("/");
	if(paths[paths.length-1] != ""){
		paths[paths.length-1] = "";
		path = paths.join("/");
	}
	// 有効期限の日付
	var extime = new Date().getTime();
	var cltime = new Date(extime + (60*60*24*1000*expiredays));
	var exdate = cltime.toUTCString();
	// クッキーに保存する文字列を生成
	var s="";
	s += c_name +"="+ escape(value);// 値はエンコードしておく
	s += "; path="+ path;
	if(expiredays){
		s += "; expires=" +exdate+"; ";
	}else{
		s += "; ";
	}
	// クッキーに保存
	document.cookie=s;
}

//IE7以下か判定
function Ie8AndUnderCheck(){	
	//if(_ua.ltIE8){
	if(_ua.ltIE7){		
		//この中のコードはIE7以下用
		//ブラウザがIE7以下
		$(".is-ie8-and-under").toggle();
	} else {
		//Cookie判定
		setCookie('setck','ok');
		CookieEnabledCheck();		
	}
}

//Cookie判定
function CookieEnabledCheck(){
	if(getCookie('setck') == 'ok'){
		//cookie有効
	}else{
		//cookie無効
		$(".no-cookie").toggle();
	}
}


$(".no-cookie,.is-ie8-and-under").css("display", "none");
Ie8AndUnderCheck();
});
</script>
<!-- スクリプトがオフの場合 -->
<noscript>
	<div class="no-script">		
	<div class="system-alert">
	  <p>現在ご使用のブラウザは、<em>JavaScriptが無効</em>になっています。</p>
		<p>お手數ですが、JavaScriptを有効にして、ご使用願います。</p>
		<p><a href="/troubleshooting/jsEnable.html" class="link-text">JavaScriptを有効にする方法</a></p>
	</div>
	</div>
</noscript>


<!-- ブラウザがIE7以下の場合 -->
<!--- 使用しているjQuery 3系はIE9以降対応なため、表示しない --->
<!---<div class="no-script is-ie8-and-under" style="display:none">    
	<div class="system-alert">
	  <p>ご使用のブラウザのバージョンは、本システムが対応しておりません。</p>
		<p>Internet Explorer(IE)は<em>バージョン8以上</em>をご使用ください。</p>
		<br />
		<p>IEのバージョンアップを実施できない場合は、Google Chromeをご使用くださいますよう、お願い申し上げます。</p>
	</div>		
</div>--->



<!-- cookieがオフの場合 -->
<div class="no-script no-cookie" style="display:none">
	<div class="system-alert">
	  <p>現在ご使用のブラウザは、<em>Cookieが無効</em>になっています。</p>
		<p>お手數ですが、Cookieを有効にして、ご使用願います。</p>
		<p><a href="/troubleshooting/cookieEnable.html" class="link-text">Cookieを有効にする方法</a></p>
	</div>
</div>



</cfprocessingdirective>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章