【问题标题】:My external css file will not load in electron app我的外部 css 文件不会加载到电子应用程序中
【发布时间】:2020-08-30 10:01:59
【问题描述】:

第一次在这里提问。我刚开始使用电子 js 制作桌面应用程序,当我尝试将外部样式表加载到我的 index.html 文件中时,它不起作用。这是我的 HTML:

<html lang="en">

<head>
<meta charset="utf-8">
<title>Bundle</title>
<meta name="viewport" content="width=device-width, inital-scale=1.0">
<link rel="stylesheet" type="style.css"
  href="https://raw.githubusercontent.com/AlessioToniolo/Bundle/master/style.css">

</head>

<body>
<div class="header-separation">Hello</div>
<script src="main.js"></script>
<script>
  /* const electron = require('electron');
  const {ipcRenderer} = electron;
  ipcRenderer.send('item:add', item);
  */
  // For other window:
  /* previous code plus
  ipcRenderer.on('item:add', (e, item) => {
  })
  */
</script>
</body>

</html>

当我最初尝试链接到我的外部样式表时,我只是使用了路径而不是 URL,但是当它不起作用时,我尝试从确实有效的 CSS 框架加载另一个样式表。我究竟做错了什么?谢谢!

【问题讨论】:

    标签: javascript html css node.js electron


    【解决方案1】:

    我认为 GitHub 不允许这样做,因为 CSP,您应该在 unpkg.com 等其他地方托管您的 CSS。

    这里是 GitHub CSP。您可以在开发工具上查看您的网络选项卡

    default-src 'none'; style-src 'unsafe-inline'; sandbox
    

    我认为是因为使用了沙盒sandbox描述here

    并且请求的内容类型是text/plain而不是text/css,所以它没有被执行。

    我刚刚试了一下,我做不到。首先你的 gits 上有错字 seperation,2 它应该是 type="text/css"

    【讨论】:

      【解决方案2】:

      尝试将 type="style.css" 设置为 type="text/css"。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-08-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-12
        • 2016-03-14
        • 1970-01-01
        相关资源
        最近更新 更多