戻る

JavaScriptを使ってユーザーエージェントで振り分ける

pc.html

<!DOCTYPE HTML>
<html lang="ja-JP">
<head>
<meta charset="UTF-8">
<script>
if(navigator.userAgent.indexOf("Android") != -1 || navigator.userAgent.indexOf("iPhone") != -1 || navigator.userAgent.indexOf("iPod") != -1){
	window.location.href="sphone.html";
}
</script>
<title>PCサイト</title>
</head>
<body>
<h1>PCサイト</h1>
</div>
</body>
</html>

sphone.html

<!DOCTYPE HTML>
<html lang="ja-JP">
<head>
<meta charset="UTF-8">
<script>
if(navigator.userAgent.indexOf("Android") == -1 && navigator.userAgent.indexOf("iPhone") == -1 && navigator.userAgent.indexOf("iPod") == -1){
	window.location.href="pc.html";
}
</script>
<title>スマートフォンサイト</title>
</head>
<body>
<h1>スマートフォンサイト</h1>
</div>
</body>
</html>

inserted by FC2 system