我正在使用Greasemonkey并尝试在特定域中添加规则.但它导致错误说The operation is insecure.
该代码在Chrome上正常运行.
该脚本运行http://mydomain.com/test/test.php
并且CSS文件是http://cdn.mydomain.com/test/css/global.css
我的功能:
function css(selector, property, value) {
for (var i=0; i<document.styleSheets.length;i++)
{
try
{
document.styleSheets[i].insertRule(selector+ ' {'+property+':'+value+'}', document.styleSheets[i].cssRules.length);
}
catch(err)
{
try // IE
{
document.styleSheets[i].addRule(selector, property+':'+value);
}
catch(err) {}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在谷歌上我发现可能是因为我试图访问跨域,所以我尝试将CSS文件的URL添加到"接受的URL"但没有结果.
我该如何解决?