LoginSignup
1
2

More than 5 years have passed since last update.

簡単!JSでスマホサイトをPCサイトにページ単位でリダイレクトさせる方法

Posted at

簡単楽ちん。
スマホのリダイレクトさせたいページに以下コードを埋め込む。


<script type="text/javascript">
// UA判別 PCでアクセスした場合PC版に飛ばす
var UA = navigator.userAgent.toLowerCase();
var file_name = window.location.href.substring(window.location.href.lastIndexOf("/")+1,window.location.href.length);
if( UA.indexOf('iphone') == -1 && UA.indexOf('ipad') == -1 && UA.indexOf('ipod') == -1 && UA.indexOf('iemobile') == -1 && UA.indexOf('tizen') == -1 && UA.indexOf('android') == -1 ){
    location.href = 'http://www.hoge.co.jp/about.html';
}
</script>

例の場合PC版のabout.htmlにリダイレクトします。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2