HTML 重定向取决于设备类型

标签 html web-frontend http-equiv

我有一个非常简单的网页:

<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/

相关文章:

html - 在 HTML 中声明字符编码

html - http-equiv Cache-Control 和 Pragma 指令是否有符合 HTML5 的替代方案?

javascript - 从 html 页面打印表格

javascript - 如何将 JavaScript 函数应用于选择表单?

javascript - Facebook 如何在聊天时改变其符号中的表情符号?

javascript - WebWorkers - 新的 Worker 不断从服务器请求相同的脚本

html - 网页的宽度设置为 980px 而不是窗口的宽度。手机网站

html - 无法在 KO 网格中选择文本

html - 单击后按钮仍保持按下状态