简体   繁体   English

html/code - 进入网站时转移到桌面/移动网站

[英]html/code - Divert to desktop/mobile site on enter the site

I'm working on a site with separate pages for mobile and desktop.我正在开发一个具有移动和桌面单独页面的网站。 I have a code that diverts people to mobile or desktop based on screen resolution.我有一个代码可以根据屏幕分辨率将人们转移到移动设备或桌面设备上。

I want to change this so the code only runs On Domain/Website Load - for example: IfPreviousDomain != this Domain run code.... (www.example.com)我想更改此代码,以便代码仅在域/网站加载时运行 - 例如: IfPreviousDomain != 此域运行代码.... (www.example.com)

The code we have now looks like this:我们现在的代码如下所示:

<script> if ( (screen.width < 1024) && (screen.height < 768) ) { 
window.location = 'http://www.example.com/Mobile.html';
}  </script>

OR或者

<script> if ( (screen.width > 1024) && (screen.height > 768) ) { 
window.location = 'http://www.example.com/';
}  </script>

if there is better code for the job please let me know.如果有更好的工作代码,请告诉我。 Also I only know basic html and Python so I don't even know what language the above code is.另外我只知道基本的 html 和 Python,所以我什至不知道上面的代码是什么语言。

The language above is JavaScript.上面的语言是 JavaScript。 I don't see any better option than the version above.我没有看到比上面的版本更好的选择。 If you wrap your code with如果你用你的代码包装

document.addEventListener("DOMContentLoaded", function(event) { 
  //here goes your code
});

then the function should only be executed on the initial load.那么该函数应该只在初始加载时执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM