ホーム

How to judge whether it is a personal computer or a smartphone with js

I would like to judge whether the terminal accessing by making js is a personal computer or a smartphone. There is no such thing as saying.

html

<p id="text">Wich one</p>

js

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {

    var p = document.getElementById('text');
    p.innerHTML = 'Mobile'

}else{

    var p = document.getElementById('text');
    p.innerHTML = 'pc'

}
Pocket
LinkedIn にシェア



新規webサービスの開発の依頼ならoffテク⭐️

低コストで、Reactなどモダン言語での新規webサービス開発を承ります

-ホーム

Copyright© off , 2020 All Rights Reserved Powered by AFFINGER5.