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. 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?
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:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.