JavaScriptでuseragentでMobileのみ検知する(2016年6月時点)

スポンサーリンク

JavaScriptでユーザーエージェントを用いてスマートフォン、タブレットデバイスのみ検知する方法。

Mozillaのサイトによると、"Mobi"の文字で検知することが推奨されている。

例:

if (navigator.userAgent.match(/Mobi/g)) { …}

*gはglobalに検索。一番初めにヒットした検索文字だけでなく、対象の全ての文字を検索

Browser detection using the user agent - HTTP | MDN
Serving different Web pages or services to different browsers is usually a bad idea. The Web is meant to be accessible to everyone, regardless of which browser ...

コメント

タイトルとURLをコピーしました