如何基于React.js中的用户代理将iOS的类添加到body标签中
我必须检测iOS用户代理并在body标签上添加额外的类。 代码如下:
const generateHTML = (html) => {
const userAgent = navigator.userAgent || navigator.vendor;
if (/android/i.test(userAgent)) {
$('html').addClass('android');
}
else if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
$('html').addClass('ios');
}
return
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
</head>
<body style="visibility: hidden;"
onLoad="document.body.style.visibility='visible'">
<div id="app">${html}</div>
</body>
</html>`;
};