Javascript 在桌面上打开我的网站上的新链接时,它会在Chrome上加载移动css
当我在我的站点上,使用鼠标中键将页面加载到新选项卡中时,它会将页面呈现为好像它在移动设备上,但实际上它在桌面上。它只是在更新之后才在Chrome上开始这样做 由于该网站是在我加入之前完成的,他们没有像应该使用的那样使用media query,而是实际使用了移动CSS文件和桌面CSS文件。根据屏幕的大小,它会加载所需的屏幕 我认为正在发生的是,当页面加载到一个新的选项卡时,它会加载到一个较小的屏幕上,使我的脚本相信它在移动设备上,但实际上它在桌面上 jQuery:Javascript 在桌面上打开我的网站上的新链接时,它会在Chrome上加载移动css,javascript,jquery,html,css,google-chrome,Javascript,Jquery,Html,Css,Google Chrome,当我在我的站点上,使用鼠标中键将页面加载到新选项卡中时,它会将页面呈现为好像它在移动设备上,但实际上它在桌面上。它只是在更新之后才在Chrome上开始这样做 由于该网站是在我加入之前完成的,他们没有像应该使用的那样使用media query,而是实际使用了移动CSS文件和桌面CSS文件。根据屏幕的大小,它会加载所需的屏幕 我认为正在发生的是,当页面加载到一个新的选项卡时,它会加载到一个较小的屏幕上,使我的脚本相信它在移动设备上,但实际上它在桌面上 jQuery: function Resolut
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;
函数解析开关(配置){
this.cutoff=document.cutoff | | 980;
此.head=$(document.querySelector(“head”);
$.extend(这个,配置);
}
ResolutionSwitcher.prototype.appendStyle=函数(url){
此.$head.append($(“”){
键入:“文本/css”,
rel:“样式表”,
href:url
}));
};
ResolutionSwitcher.prototype.removeStyle=函数(url){
这是。$head.find(“链接[href$=”+url+“]”)。删除();
};
ResolutionSwitcher.prototype.onDesktop=函数(){
这个.appendStyle(“/static/public/css/desktop.v2.css”);
这个.removeStyle(“mobile.css”);
DesktopLayout.init();
};
ResolutionSwitcher.prototype.onMobile=函数(){
这个.appendStyle(“/static/public/css/mobile.v2.css”);
这个.removeStyle(“desktop.v2.css”);
MobileLayout.init();
};
ResolutionSwitcher.prototype.checkResolution=函数(){
var\u截止值=460;
//如果屏幕小于截止值(移动)
if(this.cutoff>=屏幕宽度){
this.onMobile();
window.site_version='strict_mobile';
}
//若屏幕大于截止,但窗口小于截止,且版本尚未移动
else if(desktop\u cutoff>=window.outerWidth&&window.site\u版本!=“mobile”){
this.onMobile();
window.site_version='mobile';
//导航滚动(“#第二个列表”);
//导航滚动(“#第三列表”);
导航滚动();
}
//若屏幕和窗口都比截止点宽,并且版本还不是桌面
else if(desktop_cutoff
正在缓存您的JS。要防止缓存,请在脚本标记中添加随机int。所以把它放在一个外部文件中。@Raymond我刚刚做了,它工作了,但是它引起了一些样式问题。或者这完全是另一个问题?可能是另一个问题,除非相对路径在JS文件中,它们是。因此,请更新文件路径的位置。