Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.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 为什么';Firefox插件工作中的my page mod contentStyle字体面规则是否存在?_Javascript_Css_Firefox_Firefox Addon_Firefox Addon Sdk - Fatal编程技术网

Javascript 为什么';Firefox插件工作中的my page mod contentStyle字体面规则是否存在?

Javascript 为什么';Firefox插件工作中的my page mod contentStyle字体面规则是否存在?,javascript,css,firefox,firefox-addon,firefox-addon-sdk,Javascript,Css,Firefox,Firefox Addon,Firefox Addon Sdk,我正在尝试使用Firefox插件SDK中的page mod模块向页面中注入字体。以下是我构建的字符串: var fontString = "@font-face{" + "font-family:'Glyphicons Halflings';" + "src:url(" + data.url('fonts/glyphicons-halflings-regular.eot') + ");" + "src:url(" + data.url('fonts/glyphicons-

我正在尝试使用Firefox插件SDK中的page mod模块向页面中注入字体。以下是我构建的字符串:

var fontString = "@font-face{" +
    "font-family:'Glyphicons Halflings';" +
    "src:url(" + data.url('fonts/glyphicons-halflings-regular.eot') + ");" +
    "src:url(" + data.url('fonts/glyphicons-halflings-regular.eot') + "?#iefix) format('embedded-opentype')," +
    "url(" + data.url('fonts/glyphicons-halflings-regular.woff') + ") format('woff')," +
    "url(" + data.url('fonts/glyphicons-halflings-regular.ttf') + ") format('truetype')," +
    "url(" + data.url('fonts/glyphicons-halflings-regular.svg') + "#glyphicons-halflingsregular) format('svg');}";
在创建字符串并输出后,我将其记录到控制台:

@font-face{font-family:'Glyphicons Halflings';src:url(resource://jid1-sqpdj54n2pcvoq-at-jetpack/firefoxaddon/data/fonts/glyphicons-halflings-regular.eot);src:url(resource://jid1-sqpdj54n2pcvoq-at-jetpack/firefoxaddon/data/fonts/glyphicons-halflings-regular.eot?#iefix) format('embedded-opentype'),url(resource://jid1-sqpdj54n2pcvoq-at-jetpack/firefoxaddon/data/fonts/glyphicons-halflings-regular.woff) format('woff'),url(resource://jid1-sqpdj54n2pcvoq-at-jetpack/firefoxaddon/data/fonts/glyphicons-halflings-regular.ttf) format('truetype'),url(resource://jid1-sqpdj54n2pcvoq-at-jetpack/firefoxaddon/data/fonts/glyphicons-halflings-regular.svg#glyphicons-halflingsregular) format('svg');}
我已经测试过,这个输出CSS通过复制并粘贴到一个面板页面来工作,并且工作正常。资源URL是正确的。但是,当我尝试将其作为contentStyle规则注入其他页面时,页面无法识别字体。这是我的密码:

require("sdk/page-mod").PageMod({
    include: "*",
    contentScriptFile: [...],
    contentStyle: fontString,
    onAttach: function (worker) {
        console.log('Attached');
    }
});

我已经验证了在加载每个页面后是否调用了
onAttach
。此外,我使用同一页面模块注入的所有脚本(为了简洁起见,我没有将它们包含在代码段中)都被注入,并且工作正常。另外,如果我将
fontString
更改为类似
body{background color:red;}
的简单内容,它也可以正常工作。为什么页面无法识别字体?

这是XSS限制。如果可以将字体数据转换为数据uri
data:
,那么这可能会起作用


否则你可能不得不这样做,我们可以找人来解决这个问题。

暂时,虽然这是一个bug,但请尝试这种方法,使用组件,以便go
var{Cc,Cu,Ci}=require('chrome')在顶部,然后将其粘贴到某个位置:

var sss = Cc['@mozilla.org/content/style-sheet-service;1'].getService(Ci.nsIStyleSheetService);
var ios = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);

var css = var fontString = "@font-face{" +
    "font-family:'Glyphicons Halflings';" +
    "src:url(" + data.url('fonts/glyphicons-halflings-regular.eot') + ");" +
    "src:url(" + data.url('fonts/glyphicons-halflings-regular.eot') + "?#iefix) format('embedded-opentype')," +
    "url(" + data.url('fonts/glyphicons-halflings-regular.woff') + ") format('woff')," +
    "url(" + data.url('fonts/glyphicons-halflings-regular.ttf') + ") format('truetype')," +
    "url(" + data.url('fonts/glyphicons-halflings-regular.svg') + "#glyphicons-halflingsregular) format('svg');}";

//var cssEnc = 'data:text/css;base64,' + window.btoa(css);
var cssEnc = encodeURIComponent(css);
var cssUri = makeURI('data:text/css,' + cssEnc);
sss.loadAndRegisterSheet(cssUri, sss.USER_SHEET);

要注销样式表,请执行以下操作
sss.unregisterSheet(cssUri,sss.USER\u SHEET)

您是否看到与代码相关的CSS错误或警告?或者,您是否尝试过将css放入单独的css文件并使用contentStyleFile?我认为您不需要data.url来获取完整的资源url,相对url应该可以工作。不,相对url在contentStyleFile中不起作用。从中,>当前不能在以这种方式加载的样式表中使用相对URL。例如,考虑一个引用外部文件的CSS文件:背景:RGB(249, 249, 249)URL(‘..…/IMG/MyPix.PNG’)重复X顶部中心;如果使用contentStyleFile附加此文件,将找不到“my background.png”。作为一种解决方法,您可以为“数据”目录中的文件构建一个绝对URL