Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 某些网页的css文件无法从localhost运行_Javascript_Css - Fatal编程技术网

Javascript 某些网页的css文件无法从localhost运行

Javascript 某些网页的css文件无法从localhost运行,javascript,css,Javascript,Css,我正在尝试使用javascript来更改从firefox加载的任何网页的背景。我已经安装了ApacheWeb服务器。从firebug控制台加载站点后,我在任何站点(例如stackoverflow.com)上运行以下代码 测试1:来自本地主机的css文件 var s = document.createElement('link'); s.setAttribute('href', 'http://localhost/new1.css'); s.setAttribute('rel', 'stylesh

我正在尝试使用javascript来更改从firefox加载的任何网页的背景。我已经安装了ApacheWeb服务器。从firebug控制台加载站点后,我在任何站点(例如stackoverflow.com)上运行以下代码

测试1:来自本地主机的css文件

var s = document.createElement('link');
s.setAttribute('href', 'http://localhost/new1.css');
s.setAttribute('rel', 'stylesheet');
s.setAttribute('type', 'text/css');
document.getElementsByTagName('head')[0].appendChild(s);
alert('Stylesheet injected!');
上述代码适用于stackoverflow.com wikipidea.com。已成功从本地服务器加载new1.css文件。但这段代码不适用于google.com、yahoo.com和其他许多网站

http://localhost/new1.css

body { background-color: #0000ee !important; }
body { background-color: #0000ee !important; }
我在firebug控制台中运行代码,下面的代码出现在html的头部

<link type="text/css" rel="stylesheet" href="http://localhost/new1.css">
<link type="text/css" rel="stylesheet" href="https://dl.dropboxusercontent.com/s/cdio6v4wiqj7g1i/new1.css?dl=1&token_hash=AAFsujreqLbTBoBcn5oF4CE0x2YKzuZG4RbYS27W0b0TUA">
结果:任何现场的工程:

https://dl.dropboxusercontent.com/s/cdio6v4wiqj7g1i/new1.css?dl=1&token_hash=AAFsujreqLbTBoBcn5oF4CE0x2YKzuZG4RbYS27W0b0TUA

我在firebug控制台中运行代码,下面的代码出现在html的头部

<link type="text/css" rel="stylesheet" href="http://localhost/new1.css">
<link type="text/css" rel="stylesheet" href="https://dl.dropboxusercontent.com/s/cdio6v4wiqj7g1i/new1.css?dl=1&token_hash=AAFsujreqLbTBoBcn5oF4CE0x2YKzuZG4RbYS27W0b0TUA">


任何人都能理解为什么通过localhost提供的css文件不起作用,而dropbox提供的相同css文件适用于google.com

您无法从HTTPS网站中的HTTP加载资源


如果您查看控制台,您会看到一条警告,解释这一点。

可能是缓存问题,请尝试在Google Chrome“incognito window”中加载您的页面。抱歉,我看到了。但在这里,我尝试直接从文档根开始。你看到localhost/new1.css没有任何.public\u html etcSorry,我的错。我看得不够近,它出现在萤火虫上。阻止加载混合活动内容“”是否有任何解决方法,我想用作greasmonkey脚本