weixin_33724059 2018-10-03 18:11 采纳率: 0%
浏览 78

如何在AJAX调用中引用.CSS?

My goal is to add dark theme in slack windows application. I found so many threads which recommend some solution. Here, they refer to some CSS and that works fine.

Code that works:

document.addEventListener('DOMContentLoaded', function() {
 $.ajax({
   url: 'https://cdn.rawgit.com/laCour/slack-night-mode/master/css/raw/black.css',
   success: function(css) {
     $("<style></style>").appendTo('head').html(css);
   }
 });
});

I do not want to access these links due to security reasons so copied that CSS file on my machine and want to access that but I guess I am doing something wrong.

Following are my attempts:

Attempt-1

document.addEventListener('DOMContentLoaded', function() {
 $.ajax({
   href: 'C://LocalPath/slack/app-3.3.1/resources/app.asar.unpacked/src/static/slack_dark_theme.css',
   media: media || 'screen',
   type: 'text/css',
   rel: 'stylesheet'
   success: function(css) {
     $("<style></style>").appendTo('head').html(css);
   }
 });
});

Attempt-2

document.addEventListener('DOMContentLoaded', function() {
 $.ajax({
   url: 'C://LocalPath/slack/app-3.3.1/resources/app.asar.unpacked/src/static/slack_dark_theme.css',
   dataType:"script",
   success: function(css) {
     $("<style></style>").appendTo('head').html(css);
   }
 });
});

Attempt-3

document.addEventListener('DOMContentLoaded', function() {
 $.ajax({
   url: 'C://LocalPath/slack/app-3.3.1/resources/app.asar.unpacked/src/static/slack_dark_theme.css',
   dataType:"script",
   success: function(css) {
     $("head").append("<style>" + css + "</style>");
   }
 });
});

Attempt-4

document.addEventListener('DOMContentLoaded', function() {
 $.ajax({
   url: 'C://LocalPath/slack/app-3.3.1/resources/app.asar.unpacked/src/static/slack_dark_theme.css',
   dataType:"script",
   success: function(css) {
     $("<style type="text/css"></style>").appendTo('head').html(css);
   }
 });
});

Attempt-5

document.addEventListener('DOMContentLoaded', function() {
 $.ajax({
   url: 'file:///C://LocalPath/slack/app-3.3.1/resources/app.asar.unpacked/src/static/slack_dark_theme.css',
   success: function(css) {
     $("<style></style>").appendTo('head').html(css);
   }
 });
});
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题
    • ¥15 Python时间序列如何拟合疏系数模型