我正在尝试根据用于访问网站的子域标头设置网站样式,例如它将是:
我为每个公司在天蓝色存储位置保存了css文件
我正在尝试获取子域名,然后将样式链接添加到我的_layout页面的头部,但它似乎没有工作,任何人都可以看到我在这里做错了吗?
$(document).ready(function () {
var subdomain = window.location.host.split('.mysite.com')[0];
alert(subdomain);
$('<link rel="stylesheet" type="text/css" href="https://metalearning.blob.core.windows.net/companystyles/' + subdomain + ' >').appendTo('head');
});
这正确地让我在子域的警报提示中返回customer1或customer2,但链接未添加到布局页面的头部
答案 0 :(得分:1)
您可以尝试将其插入body
代码的末尾。
$('body').append('<link rel="stylesheet" type="text/css" href="https://metalearning.blob.core.windows.net/companystyles/' + subdomain + '>');
此更改是否适合您?
答案 1 :(得分:0)
尝试将其附加到文档中(只需将其附加到文档正文中)
<style type="text/css">
@import url(css/company1.css);
</style>
编辑,我刚试过这个:
$("body").append('<style type="text/css">@import url(css/company1.css);</style>');
似乎工作。
编辑2,这个怎么样?
$("body").append('<style type="text/css">@import url(https://metalearning.blob.core.windows.net/companystyles/' + subdomain + ');</style>');