简体   繁体   English

如何打开另一个文件index.html,具体取决于屏幕的宽度?

[英]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.

相关问题 如何使index.html根据浏览器语言或IP地址动态重定向到另一个文件 - How to make an index.html that dynamically redirects to another file depending on browser language or IP address 如何将文件 vuejs 组件导入 index.html? - how can I import a file vuejs component into index.html? 如何在 Svelte 中重命名 index.html 文件? - How can I rename index.html file in Svelte? 如何将 index.html 文件中的变量加载到 results.html 文件中? - How can I load a variable from a index.html file to a results.html file? 如何在 React 的 index.html 文件中正确包含 css 文件? - How can I properly include a css file in my index.html file in React? index.html 可以播放音频文件吗? 如果是这样,我如何实现它在后台自动播放? - Can index.html play an audio file? If so, How can I implement it to auto play in the back ground? 我怎样才能通过js保护我的index.html网站所以我只能在我的电脑上打开它? - how can i protect my index.html website by js so i can only open it on my pc? 如何使用gulp-inject将文件的内容插入到index.html中? - How can I insert the contents of a file in my index.html with gulp-inject? 如何在电子上加载 index.html 文件? - How do I load the index.html file on electron? 如何判断用户是否在index.html上? - How can I tell if a user is on index.html?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM