了解最新公司动态及行业资讯
let userAgent = navigator.userAgent;console.log(userAgent);
function detectDevice() {
let userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('mobile') !== -1 || userAgent.indexOf('android') !== -1 || userAgent.indexOf('iphone') !== -1) {
return 'Mobile';
} else {
return 'PC';
}}let deviceType = detectDevice();console.log('Device Type:', deviceType);function detectDeviceByScreenSize() {
let width = window.innerWidth;
if (width <= 768) {
return 'Mobile';
} else {
return 'PC';
}}let deviceTypeByScreenSize = detectDeviceByScreenSize();console.log('Device Type by Screen Size:', deviceTypeByScreenSize);function detectDevice() {
let userAgent = navigator.userAgent.toLowerCase();
let width = window.innerWidth;
if (userAgent.indexOf('mobile') !== -1 || userAgent.indexOf('android') !== -1 || userAgent.indexOf('iphone') !== -1 || width <= 768) {
return 'Mobile';
} else {
return 'PC';
}}let deviceType = detectDevice();console.log('Device Type:', deviceType);/* PC 样式 */body {
background-color: lightblue;}/* 手机样式 */@media only screen and (max-width: 768px) {
body {
background-color: lightgreen;
}}function detectDeviceByMediaQuery() {
if (window.matchMedia('(max-width: 768px)').matches) {
return 'Mobile';
} else {
return 'PC';
}}let deviceTypeByMediaQuery = detectDeviceByMediaQuery();console.log('Device Type by Media Query:', deviceTypeByMediaQuery);