【发布时间】:2022-12-03 21:47:41
【问题描述】:
我的网站中有一个组件用于显示下载链接,每当客户端使用 android web 视图访问我的网站时,我想删除该组件。
期望在 js 中有一个函数来确定这个但找不到任何
【问题讨论】:
标签: javascript jquery frontend
我的网站中有一个组件用于显示下载链接,每当客户端使用 android web 视图访问我的网站时,我想删除该组件。
期望在 js 中有一个函数来确定这个但找不到任何
【问题讨论】:
标签: javascript jquery frontend
您可以尝试使用 navigator.userAgent 属性来确定客户端是否正在使用 android web 视图。
function checkForWebView() {
const userAgent = navigator.userAgent;
if (userAgent.includes('Android')) {
// The client is using an Android device.
// Check if the user agent string contains the name of a known Android web view.
if (userAgent.includes('Chrome') || userAgent.includes('Firefox') || userAgent.includes('SamsungBrowser')) {
// The client is using a web view.
return true;
} else {
// The client is not using a web view.
return false;
}
} else {
// The client is not using an Android device.
return false;
}
}
【讨论】: