如何根据 URL 或客户端加载 CSS 文件? [英] How to load a CSS file based on a URL or client?

查看:44
本文介绍了如何根据 URL 或客户端加载 CSS 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Sencha touch 应用程序中有两个 CSS 文件.让我们称它们为 A.cssB.css.根据 URL,我希望应用程序加载不同的 CSS.

I have two CSS files in my Sencha touch application. Lets call them A.css and B.css. Based on the URL I want the application to load different CSS.

假设 URL 1 是 www.website.com/#1 所以为此我想加载 A.css.类似地,URL 2 是 www.website.com/#2 所以为此我想加载 B.css

Lets say URL 1 is www.website.com/#1 so for this I would like to load A.css. similarly URL 2 is www.website.com/#2 so for this I would like to load B.css

是否可以根据 URL 动态加载 CSS?

Is it possible to load CSS dynamically based on the URL?

推荐答案

您可以为此使用 JavaScript 正则表达式.

You can use JavaScript Regex for this.

非常简单的方法:

    // For www.website.com/#1
    if (/www.website.com\/#1/.test(window.location.href)) {
        /* Your Code Here For Loading Css */
    }

    // For www.website.com/#2
    if (/www.website.com\/#1/.test(window.location.href)) {
        /* Your Code Here For Loading Css */
    }

我希望这有帮助!!!

这篇关于如何根据 URL 或客户端加载 CSS 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆