Открывая новую ссылку на моем сайте на рабочем столе, он загружает мобильную CSS вместо Chrome - PullRequest
0 голосов
/ 04 октября 2019

Когда я нахожусь на своем сайте и использую среднюю кнопку мыши для загрузки страницы в новую вкладку, она отображает страницу, как если бы она была на мобильном телефоне, но на самом деле она на рабочем столе. Он только недавно начал делать это в 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;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...