Browser
coderljw 2024-10-13 小于 1 分钟
# 1. 获取设备类型
/**
* @return {string} Mobile | Desktop
*/
export const getDeviceType = () =>
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent,
)
? 'Mobile'
: 'Desktop'
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 2. 检测浏览器是否刷新
/**
* @return {boolean} true | false
*/
export const checkReload = () => {
return (
window.performance.navigation?.type === 1 ||
(
window.performance.getEntriesByType(
'navigation',
)[0] as PerformanceNavigationTiming
)?.type === 'reload'
)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13