[英]How can I open another file index.html, depending on the width of the screen?
Here's my problem. 这是我的问题。
I've got finished page (html + css + js), but I want to do a mobile version, with other html files, another index.html and css file. 我已经完成了页面(html + css + js),但我想做一个移动版本,其他html文件,另一个index.html和css文件。 What do I need to add the code to the main page, that when i open site on device with screen width less than 800 pixels it will launching the mobile version?
我需要将代码添加到主页面,当我在屏幕宽度小于800像素的设备上打开网站时,它会启动移动版本吗?
It may not be the answer you want, however this script will re-direct the user if they are utilizing a touch screen device (ie Phone, tablet) 它可能不是您想要的答案,但是如果用户使用触摸屏设备(即手机,平板电脑),此脚本将重定向用户
<script>
if( 'ontouchstart' in window ){
window.location = 'mobile/index.html';
}
</script>
Put this in your onload: 把它放在你的onload中:
if(window.innerWidth < 800{
window.location = '/m/index.html';
}
or (this is as cross-browser) 或(这是跨浏览器)
if(window.screen.width < 800{
window.location = '/m/index.html';
}
Create your mobile version on subdomain or subfolder and add JavaScript mobile user detection and redirect them to mobile page 在子域或子文件夹上创建您的移动版本,并添加JavaScript移动用户检测并将其重定向到移动页面
https://github.com/sebarmeli/JS-Redirection-Mobile-Site https://github.com/sebarmeli/JS-Redirection-Mobile-Site
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.