在Firefox中,我如何--disable-web-security在Chrome中完成相同的操作.这已经发布了很多,但从来没有一个真正的答案.大多数是附加组件的链接(其中一些在最新的Firefox中不起作用或根本不起作用)和"你只需要在服务器上启用支持".
同样,这仅用于在推送到prod之前进行测试,然后,这将是允许的域.
我有一个.svg文件,想要将它嵌入我的d3-graphic的svg结构中.
我还需要通过某些g元素的id引用附加到g元素的所有路径/多边形.
我尝试了不同的方法来嵌入和引用svg(g's),但由于某些原因它不起作用:
(1)第一次尝试
// Firefox displays my svg but when i open it with Chrome the svg
//is not displayed (just default placeholder icon)
// I can't reference the svg-g id's with d3.select functions.
main_chart_svg
.append("svg:image")
.attr("xlink:href", "mySVGpicture.svg")
.attr("x", "50")
.attr("y", "50")
.attr("width", "500")
.attr("height", "500");
main_chart_svg.select("#anIdWhichIsInTheSvgFile").remove(); //// This doesn't work
Run Code Online (Sandbox Code Playgroud)
(2)第二次尝试
// This displays the svg but -not- inside my main-chart-svg. I want to keep the graphic
//things seperate to html-stuff.
d3.xml("mySVGpicture.svg", "image/svg+xml", function(xml) {
document.body.appendChild(xml.documentElement);
});
//----------or----------// …Run Code Online (Sandbox Code Playgroud) 我一直在关注使用Javascript访问SVG元素的示例,但我无法让它工作.这段代码有什么问题?
使用Javascript:
var objTag = document.getElementById('esc-seconds-1s');
objTag.addEventListener('load', function() {
var svgDoc = objTag.contentDocument;
var cc3 = svgDoc.getElementById('cc3');
cc3.setAttribute('fill', 'red');
}, false);
Run Code Online (Sandbox Code Playgroud)
我收到以下控制台错误:
Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLObjectElement': Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
Run Code Online (Sandbox Code Playgroud)
我认为这个错误有点失误.错误来自contentDocument行,所以我认为这不是因为相同的原始策略.另外,我在SVG文件中没有任何xlink行.这是我的SVG的顶部:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
Run Code Online (Sandbox Code Playgroud)
SVG显示正常,为什么objTag.contentDocument调用失败?
html:
<object class="esc-seven-segment" id="esc-seconds-1s"
type="image/svg+xml" data="images/seven-segment-digit.svg"></object>
Run Code Online (Sandbox Code Playgroud)
谢谢,
-Andres