【问题标题】:html/code - Divert to desktop/mobile site on enter the sitehtml/code - 在进入网站时转移到桌面/移动网站
【发布时间】:2020-01-10 18:48:08
【问题描述】:

我正在开发一个具有不同页面的移动设备和桌面网站。我有一个代码,可以根据屏幕分辨率将人们转移到移动设备或桌面。

我想更改此设置,以便代码仅在域/网站加载时运行 - 例如:IfPreviousDomain != this Domain run code.... (www.example.com)

我们现在的代码如下所示:

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

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

如果有更好的工作代码,请告诉我。另外我只知道基本的 html 和 Python,所以我什至不知道上面的代码是什么语言。

【问题讨论】:

  • 使用mobiledetect.net可以检查用户服务器端而不是客户端的设备

标签: php html web


【解决方案1】:

上面的语言是 JavaScript。我没有看到比上述版本更好的选择。如果你用

包装你的代码
document.addEventListener("DOMContentLoaded", function(event) { 
  //here goes your code
});

那么函数应该只在初始加载时执行。

【讨论】:

  • 你好 - 我会把它放在页面的头部还是其他地方?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-02
相关资源
最近更新 更多