html手机跳转pc跳转
时间: 2023-09-18 18:10:32 浏览: 52
可以通过在 HTML 页面中添加 JavaScript 代码来实现手机跳转 PC 和 PC 跳转的功能。下面是两个示例代码:
1. 手机跳转 PC:
```html
<script>
// 判断是否为手机访问
if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
// 跳转到 PC 网站
window.location.href = "http://www.example.com/pc";
}
</script>
```
2. PC 跳转手机:
```html
<script>
// 判断是否为 PC 访问
if(!/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
// 跳转到手机网站
window.location.href = "http://m.example.com";
}
</script>
```
这些代码可以在 HTML 页面的 `<head>` 或 `<body>` 标签中添加。
相关问题
html 自动判断h5 跳转pc链接,手机打开不变
你可以使用以下的 HTML 代码,通过 JavaScript 判断用户是在手机上还是在 PC 上访问,然后自动跳转到相应的链接:
```html
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript">
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
// do nothing, stay on the same page
} else {
window.location.href = "pc.html";
}
</script>
</head>
<body>
<!-- Your website content here -->
</body>
</html>
```
这段代码会判断用户的设备是否是移动设备,如果是,就会显示原来的页面内容不变。如果用户在 PC 上访问,就会自动跳转到 pc.html 页面。
html 自动判断h5 跳转手机链接,pc打开不变
你可以使用以下的 HTML 代码,通过 JavaScript 判断用户是在手机上还是在 PC 上访问,然后自动跳转到相应的链接:
```html
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript">
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
window.location.href = "mobile.html";
}
</script>
</head>
<body>
<!-- Your website content here -->
</body>
</html>
```
这段代码会判断用户的设备是否是移动设备,如果是,就会自动跳转到 mobile.html 页面。如果用户在 PC 上访问,就会显示原来的页面内容不变。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)