Skip to content

Instantly share code, notes, and snippets.

@coolniikou
Created January 28, 2012 19:19
Show Gist options
  • Select an option

  • Save coolniikou/1695484 to your computer and use it in GitHub Desktop.

Select an option

Save coolniikou/1695484 to your computer and use it in GitHub Desktop.
<script src="js/jquery_1.6.4.min.js" type="text/javascript"></script>
<script src="js/jquery.cookie.js" type="text/javascript"></script>
function detect_device() {
var user_agent = [
'iPhone',
'iPad',
'iPod',
'Android'
];
var pattern = new RegExp(user_agent.join('|^'), 'i');
return pattern.test(navigator.userAgent);
}
function smartphone_site() {
var message = confirm("スマートフォンサイトを表示しますか?");
if(message == true) {
$.cookie('detect_device_mode', 'smartphone', {path: '/'});
location.href = "./smartphone/";
} else {
$.cookie('detect_device_mode', 'pc', {path: '/'});
}
}
if(detect_device() && $.cookie('detect_device_mode') == null) {
smartphone_site();
} else if($.cookie('detect_device_mode') == 'smartphone'); {
location.href = "./smartphone/";
}
<a onclick="smartphone_site" href="javascript:void(0)">change to smartphone_site</a>
#mod_rewite enabled on
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT}(iPhone|iPod)
RewriteCond %{QUERY_STRING} !mode=pc
RewriteRule ^$ /smartphone/ [R]
RewriteCond %{HTTP_USER_AGENT} iPad
RewriteCond %{QUERY_STRING} !mode=pc
RewriteRule ^$ /smartphone/ [R]
RewriteCond %{HTTP_USER_AGENT} Android
RewriteCond %{QUERY_STRING} !mode=pc
RewriteRule ^$ /smartphone/ [R]
RewriteCond %{QUERY_STRING} !mode=pc
function detact_device() {
var user_agent = [
'iPhone',
'iPad',
'iPod',
'Android'
];
var pattern = new RegExp(user_agent.join('|^'), 'i');
return pattern.test(navigator.userAgent);
}
if(detect_device()) {
location.href = "/smartphone/"
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment