javascript - 在桌面上我的网站上打开新链接时,它会在 Chrome 上加载移动 CSS
问题描述
当我在我的网站上并使用鼠标中键在新选项卡中加载页面时,它会将页面呈现为好像它在移动设备上,但它实际上是在桌面上。它最近才在更新后开始在 Chrome 上执行此操作。
由于该网站在我加入之前完成,他们并没有像他们应该使用的那样使用媒体查询,但实际上使用了移动 CSS 文件和桌面 CSS 文件。根据屏幕的大小,它会加载所需的屏幕。
我认为正在发生的是,当页面在新选项卡中加载时,它会将其加载到较小的屏幕中,使我的脚本相信它在移动设备上,但实际上它在桌面上。
jQuery:
function ResolutionSwitcher(config) {
this.cutoff = document.cutoff || 980;
this.$head = $(document.querySelector("head"));
$.extend(this, config);
}
ResolutionSwitcher.prototype.appendStyle = function(url) {
this.$head.append($("<link/>", {
type: "text/css",
rel: "stylesheet",
href: url
}));
};
ResolutionSwitcher.prototype.removeStyle = function(url) {
this.$head.find("link[href$='" + url + "']").remove();
};
ResolutionSwitcher.prototype.onDesktop = function() {
this.appendStyle("/static/public/css/desktop.v2.css");
this.removeStyle("mobile.css");
DesktopLayout.init();
};
ResolutionSwitcher.prototype.onMobile = function() {
this.appendStyle("/static/public/css/mobile.v2.css");
this.removeStyle("desktop.v2.css");
MobileLayout.init();
};
ResolutionSwitcher.prototype.checkResolution = function() {
var desktop_cutoff = 460;
// if screen is smaller than cutoff (mobile)
if(this.cutoff >= screen.width) {
this.onMobile();
window.site_version = 'strict_mobile';
}
// if screen is bigger than cutoff but window is smaller than cutoff and version is not already mobile
else if(desktop_cutoff >= window.outerWidth && window.site_version != 'mobile') {
this.onMobile();
window.site_version = 'mobile';
// navScrolling('#secondList');
// navScrolling('#thirdList');
navScrolling();
}
// if screen and window are both wider than cutoff and version is not already desktop
else if(desktop_cutoff < window.outerWidth && window.site_version != 'desktop') {
this.onDesktop();
window.site_version = 'desktop';
// navScrolling('#secondList');
// navScrolling('#thirdList');
navScrolling();
}
};
return ResolutionSwitcher;
解决方案
推荐阅读
- html - Why does my footer have elements under it?
- c - AES decryption without padding in crypt file
- python - 使用带有多个参数的函数与`map`
- chart.js - chart.js - 将企业设计添加到图表
- hadoop - 将数据从 Apache Hadoop 迁移到 Cloudera Hadoop
- javascript - 使用 JQuery 设置新大小不起作用
- git - 如何在旧版本的 abc 文件中提交我的更改,而 git 具有相同的 abc 文件以及其他开发人员的新更改?
- python - 如何修复此 AttributeError?
- apache-flink - Apache Flink:如何使用跳过策略?
- node.js - 如何在环回中为 API 请求动态绑定数据源