我有一个非常简单的网页:
<html>
<head>
<meta http-equiv="Refresh" content="0; url='https://www.website1.com'" />
</head>
<body>
</body>
</html>
我不想总是重定向到同一个网站,而是想重定向到 website1 或 website2,具体取决于用户是使用移动设备还是计算机上的浏览器。我是前端 Web 开发的新手,因此我们将非常感谢您提供的任何帮助。
谢谢!
最佳答案
您应该使用 Javascript。根据userAgent
检查设备类型,然后重定向到新网站
<script>
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// redirects if mobile
window.location('https://example.com')
} else {
// redirects if whatever else
window.location('https://example2.com')
}
</script>
关于HTML 重定向取决于设备类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71712911/