Skip to content

@utilslib/web/IS_PHONE

IS_PHONE

函数签名

typescript
function IS_PHONE() { ... }
点击查看源码
js
/**
 * 检测平板设备
 * @returns 平板设备判断结果
 */
function isTablet() {
  const userAgent = navigator.userAgent.toLowerCase();
  return /ipad|android(?!.*mobile)|tablet/.test(userAgent);
}
// ============ 设备类型检测 ============
/** 平板设备 */
const IS_TABLET = isTablet();
/**
 * 检测手机设备
 * @returns 手机设备判断结果
 */
function isPhone() {
  const userAgent = navigator.userAgent.toLowerCase();
  return (
    /mobile|android|iphone|ipod|blackberry|iemobile|opera mini/.test(
      userAgent,
    ) && !IS_TABLET
  );
}
/** 手机设备 */
export const IS_PHONE = isPhone();
ts
/**
 * 检测平板设备
 * @returns 平板设备判断结果
 */
function isTablet() {
  const userAgent = navigator.userAgent.toLowerCase();
  return /ipad|android(?!.*mobile)|tablet/.test(userAgent);
}

// ============ 设备类型检测 ============
/** 平板设备 */
const IS_TABLET = isTablet();

/**
 * 检测手机设备
 * @returns 手机设备判断结果
 */
function isPhone() {
  const userAgent = navigator.userAgent.toLowerCase();
  return (
    /mobile|android|iphone|ipod|blackberry|iemobile|opera mini/.test(
      userAgent,
    ) && !IS_TABLET
  );
}

/** 手机设备 */
export const IS_PHONE = isPhone();

如有错误,请提交issue :::