[英]How to make an index.html that dynamically redirects to another file depending on browser language or IP address
[英]How can I open another file index.html, depending on the width of the screen?
这是我的问题。
我已经完成了页面(html + css + js),但我想做一个移动版本,其他html文件,另一个index.html和css文件。 我需要将代码添加到主页面,当我在屏幕宽度小于800像素的设备上打开网站时,它会启动移动版本吗?
它可能不是您想要的答案,但是如果用户使用触摸屏设备(即手机,平板电脑),此脚本将重定向用户
<script>
if( 'ontouchstart' in window ){
window.location = 'mobile/index.html';
}
</script>
把它放在你的onload中:
if(window.innerWidth < 800{
window.location = '/m/index.html';
}
或(这是跨浏览器)
if(window.screen.width < 800{
window.location = '/m/index.html';
}
在子域或子文件夹上创建您的移动版本,并添加JavaScript移动用户检测并将其重定向到移动页面
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.