Created
November 5, 2013 06:13
-
-
Save hideki-a/7314674 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var movePCSiteBtn = document.querySelector(".btn-pcsite a"); | |
function movePCSite(e) { | |
var xhr = new XMLHttpRequest(), | |
url = location.href, | |
pcUrl = url.replace("/sp/", "/"); | |
e.preventDefault(); | |
xhr.open("HEAD", pcUrl, true); | |
xhr.send(); | |
xhr.onreadystatechange = function () { | |
if (xhr.status === 200) { | |
location.href = pcUrl; | |
} else { | |
location.href = "/?viewmode=pc"; | |
} | |
} | |
} | |
movePCSiteBtn.addEventListener("click", movePCSite, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SDJL; | |
if(!SDJL) { | |
SDJL = {}; | |
} else if(typeof SDJL !== "object") { | |
throw new Error("Namespace 'SDJL' already exists."); | |
} | |
// ------------------------ | |
// User-Agent簡易判定 | |
// (Ver. 2.0) | |
// ------------------------ | |
SDJL.mobile = (function() { | |
var ua = navigator.userAgent; | |
var ret = { | |
ios : false, | |
android : false, | |
windows : false, | |
smartphone : false | |
}; | |
if(ua.indexOf("iPhone") > 0 || ua.indexOf("iPad") > 0 || ua.indexOf("iPod") > 0) { | |
// iOS搭載端末 | |
ret.ios = true; | |
if(ua.indexOf("iPad") === -1) { | |
ret.smartphone = true; | |
} | |
} else if(ua.indexOf("Android") > 0) { | |
// Android搭載端末 | |
ret.android = true; | |
if(ua.indexOf("Mobi") > 0) { | |
ret.smartphone = true; | |
} | |
} else if(ua.indexOf("Windows Phone") > 0) { | |
// Windows搭載端末 | |
ret.windows = true; | |
ret.smartphone = true; | |
} | |
return ret; | |
}()); | |
(function () { | |
if (!SDJL.mobile.smartphone) { | |
return; | |
} | |
if (sessionStorage.viewmode === undefined) { | |
sessionStorage.viewmode = ""; | |
} else if (!!(location.search.indexOf("viewmode=pc") > -1)) { | |
sessionStorage.viewmode = "pc"; | |
} | |
if (sessionStorage.viewmode === "") { | |
if( confirm( 'このサイトにはスマートフォン用のサイトがあります。\n表示しますか?' ) ) { | |
sessionStorage.viewmode = "sp"; | |
location.href = '/sp/'; | |
} else { | |
sessionStorage.viewmode = "pc"; | |
} | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment